php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51533 [recursive reference In Array] Nesting level too deep
Submitted: 2010-04-11 19:35 UTC Modified: 2015-06-08 20:02 UTC
Votes:18
Avg. Score:4.7 ± 0.6
Reproduced:16 of 16 (100.0%)
Same Version:14 (87.5%)
Same OS:12 (75.0%)
From: neel dot basu dot z at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.2 OS: Linux
Private report: No CVE-ID: None
 [2010-04-11 19:35 UTC] neel dot basu dot z at gmail dot com
Description:
------------
When there is recursive reference in an array comparison yields Fatal Error.
Both == and === operators yields the same.

//-------
If It is not a Bug then Recursion Detection is IMPOSSIBLE in PHP.
cause spl_object_hash() doesn't work on array or scaler types.

Test script:
---------------
<?php
error_reporting(255);
ini_set('display_errors','On');
header('Content-Type: text/plain');

$a = array();
$a[0] = &$a;
var_dump($a === $a[0]);
var_dump($a == $a[0]);

?>


Expected result:
----------------
boolean true or false

Actual result:
--------------
Fatal error: Nesting level too deep - recursive dependency? in /Server/http/php-bugs/nesting.php on line 8

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-11 19:38 UTC] neel dot basu dot z at gmail dot com
**If It is not a Bug then Recursive Reference Detection is IMPOSSIBLE in PHP.
cause spl_object_hash() doesn't work on array or scaler types.
 [2011-07-02 00:36 UTC] trefighter2334 at aol dot com
Any word on this? I'm also experiencing this bug in both Ubuntu (Zend Server AND 
vanilla PHP) and Windows 7 (Zend Server).

I guess I'm off to go find some hackish way to detect array recursion.
 [2012-02-08 10:56 UTC] herb at bobbingwide dot com
There is a comment in http://us.php.net/manual/en/function.is-array.php#98156
which suggests using casting to array to check if an array is actually an array. I was 
using this solution within a function that returns a default if the array index is not 
defined. It worked quite nicely until I tried to apply it to $GLOBALS  and I got the 
Nesting level too deep.

So I'm looking for another, highly efficient, solution that won't issue php notices for 
undefined indexes.

Test script:
<?php $GLOBALS == $GLOBALS;
Expected result:

Actual result:
Fatal error: Nesting level too deep - recursive dependency?
 [2015-06-08 20:02 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2015-06-08 20:02 UTC] cmb@php.net
This issue has been fixed as of PHP 5.3.15 and PHP 5.4.5, see
<http://3v4l.org/pCoou> and <http://3v4l.org/t5UWP>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC