php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39356 in_array() causes "Nesting level too deep" fatal error
Submitted: 2006-11-03 03:04 UTC Modified: 2007-08-17 12:17 UTC
Votes:8
Avg. Score:4.8 ± 0.4
Reproduced:7 of 7 (100.0%)
Same Version:6 (85.7%)
Same OS:3 (42.9%)
From: 7am dot online at gmail dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 5.2.0 OS: Windows XP
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 7am dot online at gmail dot com
New email:
PHP Version: OS:

 

 [2006-11-03 03:04 UTC] 7am dot online at gmail dot com
Description:
------------
Doing a in_array() check against an array containing objects with recursive dependency causes a "Nesting level too deep - recursive dependency?" fatal error.

Reproduce code:
---------------
<?php 
class A
{
	public $b;
}

class B
{
	public $a;
}

$a = new A;
$b = new B;
$b->a = $a;
$a->b = $b;

$test = array($a, $b);

var_dump(in_array($a, $test));

Expected result:
----------------
bool(true), as in PHP5.1.6

Actual result:
--------------
Fatal error: Nesting level too deep - recursive dependency? in [FILENAME] on line 19

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-03 14:01 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

In php 5 objects are passed by reference, so your code does in  
fact create a circular dependency. 
 [2006-11-04 14:47 UTC] cynic@php.net
http://php.net/in_array is completely quiet about references

this is a change from 5.1 so it should at least be a documentation problem.
 [2006-11-23 18:24 UTC] ken at smallboxsoftware dot net
I am experiencing this issue as well. Seems like a fairly large change not to document. Also "==" can no longer be used to compare objects of this configuration while "===" still can. Perhaps the functionality behind "===" could be used in the in_array function when comparing objects?
 [2007-06-15 05:35 UTC] judas dot iscariote at gmail dot com
This behaviour has been corrected in current 5_2 CVS, if now first try with  === on objects and then with "==" effectively helping to avoid the recursive dependency in **some** cases like the test case of the reporter.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Nov 25 12:01:31 2024 UTC