I want to point out that debug_backtrace() in new versions of php can detect recursion // circular references .. avoiding memory consumption.
Example:
<?php
class ParentClass {
public function __construct()
{
$this->_child = new ChildClass($this);
var_dump(debug_backtrace());
}
}
class ChildClass {
public function __construct(ParentClass $p)
{
$this->_parent = $p;
}
}
$test = new ParentClass();
?>
Output:
array(1) {
[0]=>
array(7) {
["file"]=>
string(23) "/home/jcm/testdebug.php"
["line"]=>
int(18)
["function"]=>
string(11) "__construct"
["class"]=>
string(11) "ParentClass"
["object"]=>
object(ParentClass)#1 (1) {
["_child"]=>
object(ChildClass)#2 (1) {
["_parent"]=>
*RECURSION*
}
}
["type"]=>
string(2) "->"
["args"]=>
array(0) {
}
}
}
Attention in the *RECURSION* hint provided