Pyh.conf’25: a new PHP conference for the Russian-speaking community

Voting

: five plus one?
(Example: nine)

The Note You're Voting On

jcmargentina at gmail dot com
5 years ago
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

<< Back to user notes page

To Top