go to bug id or search bugs for
Is it expected behaviour that === can trigger a Nesting level too deep error?
$a = array(&$a);
$a === $a;
I would expect $a === $a to return true.
$ php test.php
PHP Fatal error: Nesting level too deep - recursive dependency? in /srv/www/htdocs/test.php on line 3
Fatal error: Nesting level too deep - recursive dependency? in /srv/www/htdocs/test.php on line 3
$ php -v
PHP 5.4.3 (cli) (built: May 26 2012 22:29:08)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
Add a Patch
Add a Pull Request
I can confirm this on Windows. I also tried more cases:
For arrays: $a = array(); $a = &$a;
For objects: $a = new stdClass; $a->b = &$a;
Results for comparisons of $a, $b
Type PHP Operator Result
arrays 4.4.5 == fatal
arrays 4.4.5 === fatal
objects 4.4.5 == fatal
objects 4.4.5 === fatal
arrays 5.2.6 == fatal
arrays 5.2.6 === fatal
objects 5.2.6 == true
objects 5.2.6 === true
arrays 5.3.5 == fatal
arrays 5.3.5 === fatal
objects 5.3.5 == true
objects 5.3.5 === true
arrays 5.4.3 == fatal
arrays 5.4.3 === fatal
objects 5.4.3 == true
objects 5.4.3 === true
So this was fixed (either intentionally or along with general changes to object handling) in PHP 5 for objects but not for arrays.
I think the problem is your test script:
$a = array(&$a); <<<<<<< HERE
$a === $a;
you are passing the value of $a by reference, and to invoke the value then it
remove the & and it works
I've committed a change that will return immediately true the comparison between same array. So, at least your '$a = array(&$a); $a === $a;' will works.
@carloschilazo of course removing the & fixes the error. You realize this is a bugreport right?
My point is that I think the === operator should still return true or false. In this case true as $a and $a are the same object.
My testcase was a little ambiguous, shiranai7's version is better: $a = array(); $a = &$a;.
Didn't see your reply, that sounds good Felipe.., will check it out tomorrow.. thanks.
I have the same issue in a logger method stringify all values into a readable format (Zend\Log\Formatter\Base::normalize) which ever fail if the value contains a self referencing entry. It's simply not possible to check this case so in will result in an infinite loop or we get the fatal here described.
AND on logging using the error handler there is a $context argument containing such a self reference :(
This issue has been fixed as of PHP 5.3.15 and 5.4.5, see
I don't think this has been completely fixed. Test case:
$foo = ;
$foo = [ &$foo ];
array_search( $foo, $foo );