php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62171 "Nesting level too deep - recursive dependency?" in case of ===
Submitted: 2012-05-27 14:40 UTC Modified: 2016-04-02 16:20 UTC
Votes:8
Avg. Score:4.1 ± 0.9
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:3 (60.0%)
From: ray dot burgemeestre at gmail dot com Assigned:
Status: Re-Opened Package: Scripting Engine problem
PHP Version: 5.4.3 OS: linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-05-27 14:40 UTC] ray dot burgemeestre at gmail dot com
Description:
------------
Is it expected behaviour that === can trigger a Nesting level too deep error?

Test script:
---------------
<?php
$a = array(&$a);
$a === $a;
?>

Expected result:
----------------
I would expect $a === $a to return true.

Actual result:
--------------
$ 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-28 15:56 UTC] shiranai7 at hotmail dot com
I can confirm this on Windows. I also tried more cases:

For arrays: $a = array(); $a[0] = &$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.
 [2012-06-03 20:54 UTC] carloschilazo at gmail dot com
I think the problem is your test script:

<?php
$a = array(&$a); <<<<<<< HERE
$a === $a;
?>

you are passing the value of $a by reference, and to invoke the value then it 
calls itself.

remove the & and it works
 [2012-06-03 21:31 UTC] felipe@php.net
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.
 [2012-06-03 21:31 UTC] felipe@php.net
-Package: *Programming Data Structures +Package: Scripting Engine problem
 [2012-06-03 21:36 UTC] ray dot burgemeestre at gmail dot com
-Package: Scripting Engine problem +Package: *Programming Data Structures
 [2012-06-03 21:36 UTC] ray dot burgemeestre at gmail dot com
@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[0] are the same object.
My testcase was a little ambiguous, shiranai7's version is better:  $a = array(); $a[0] = &$a;.
 [2012-06-03 21:40 UTC] ray dot burgemeestre at gmail dot com
Didn't see your reply, that sounds good Felipe.., will check it out tomorrow.. thanks.
 [2013-06-08 09:58 UTC] marc-bennewitz at arcor dot de
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 :(
 [2015-06-05 11:49 UTC] cmb@php.net
-Status: Open +Status: Closed -Package: *Programming Data Structures +Package: Scripting Engine problem -Assigned To: +Assigned To: cmb
 [2015-06-05 11:49 UTC] cmb@php.net
This issue has been fixed as of PHP 5.3.15 and 5.4.5, see
<http://3v4l.org/Y6ZKh>.
 [2016-04-02 14:21 UTC] ori at wikimedia dot org
I don't think this has been completely fixed. Test case:

<?php
$foo = [];
$foo[] = [ &$foo ];
array_search( $foo, $foo );

https://3v4l.org/3XMq5
 [2016-04-02 16:20 UTC] cmb@php.net
-Status: Closed +Status: Re-Opened -Assigned To: cmb +Assigned To:
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC