Bug #35277 [Sus->Csd]: incorrect recursion detection
| From: | felipe@php.net | Date: | Sun, 07 Nov 2010 20:05:00 +0000 |
| Subject: | Bug #35277 [Sus->Csd]: incorrect recursion detection | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-155826@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=35277&edit=1
ID: 35277
Updated by: felipe@php.net
Reported by: lsmith@php.net
Summary: incorrect recursion detection
-Status: Suspended
+Status: Closed
Type: Bug
Package: Arrays related
Operating System: *
PHP Version: 6CVS, 5CVS
Assigned To: dmitry
Block user comment: N
New Comment:
Nowadays we got the expected result.
array(1) {
[0]=>
array(0) {
}
}
Previous Comments:
------------------------------------------------------------------------
[2007-03-05 18:24:40] sveta at microbecal dot com
Seems this bug affects comparision of objects which contains references
to themself:
$cat >comparision.php
<?php
class A{
private $a;
public function __construct()
{
$this->a = $this;
}
}
$a = array(new A, 1);
$b = array(new A, 1);
var_dump($a == $b);
?>
^C
$php comparision.php
Fatal error: Nesting level too deep - recursive dependency? in
/users/ssmirnova/comparision.php on line 15
------------------------------------------------------------------------
[2005-11-18 16:16:40] dmitry@php.net
The reason of this bug is IS_CV variables.
PHP doesn't increment/decrement refcount during fetching, also the order
of fetches may be changed. In 5.1 and lvalue of "$a[] = $a" is evaluated
before rvalue and changes rvalue (addes new element to array). Then $a
is assigned into this element. As a result we got circular data
structure where we shouldn't.
The same bug occurs with list()
Reproduce code:
---------------
<?php
$b = array("1","2","3");
list($a, $b, $c) = $b;
var_dump($a); //should print "1" (not "2")
var_dump($b);
var_dump($c);
$b = array("1","2","3");
list($a, $b[0], $c) = $b;
var_dump($a); //should print "1" (not "2")
var_dump($b);
var_dump($c);
?>
Expected result:
----------------
string(1) "1"
string(1) "2"
string(1) "3"
string(1) "1"
array(3) {
[0]=>
string(1) "2"
[1]=>
string(1) "2"
[2]=>
string(1) "3"
}
string(1) "3"
Actual result:
--------------
string(1) "2"
string(1) "2"
string(1) "3"
string(1) "2"
array(3) {
[0]=>
string(1) "2"
[1]=>
string(1) "2"
[2]=>
string(1) "3"
}
string(1) "3"
------------------------------------------------------------------------
[2005-11-18 15:39:56] lsmith@php.net
Description:
------------
PHP 5.1.0 seems to be overly paranoid when trying to detect a recursion.
I do not know the internals but I do not think this is a duplicate of
http://bugs.php.net/bug.php?id=29389.
Reproduce code:
---------------
$a = array(); $a[] = $a; var_dump($a);
Expected result:
----------------
array(1) { [0]=> array(0) { } }
Actual result:
--------------
array(1) { [0]=> array(1) { [0]=> *RECURSION* } }
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=35277&edit=1