#44128 [Opn->Bgs]: Incorrect recursion detection for undefined variable
| From: | dmitry@php.net | Date: | Wed, 20 Feb 2008 14:26:17 +0000 |
| Subject: | #44128 [Opn->Bgs]: Incorrect recursion detection for undefined variable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-122504@lists.php.net to get a copy of this message | ||
ID: 44128
Updated by: dmitry@php.net
Reported By: felipensp at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
PHP Version: 5.3CVS-2008-02-15 (CVS)
-Assigned To:
+Assigned To: dmitry
New Comment:
Your expectation is wrong:
In your second example two variables refer to the same NULL value.
(first element of array and variable $a)
Compare the output of the following two scripts
<?php
$x = array(&$a);
var_dump($x);
?>
Actual result:
--------------
array(1) {
[0]=>
&NULL
}
<?php
$x = array(&$a);
unset($a);
var_dump($x);
?>
Actual result:
--------------
array(1) {
[0]=>
NULL
}
In the third example you assign the array from second example to $a,
but $a is a reference, so the assignment will update the first element
of array too.
<?php
$b = array(&$a);
var_dump($b);
$a = $b;
var_dump($b);
?>
Actual result:
--------------
array(1) {
[0]=>
&NULL
}
array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
All results are the same as they should be.
Previous Comments:
------------------------------------------------------------------------
[2008-02-15 12:48:42] felipensp at gmail dot com
Description:
------------
Undefined variables non-reference/reference as item of an array has
different behavior.
Reproduce code:
---------------
1:
felipe@felipe:~/php5$ sapi/cli/php -r 'var_dump($a =array($a));'
2:
felipe@felipe:~/php5$ sapi/cli/php -r 'var_dump(array(&$a));'
3:
felipe@felipe:~/php5$ sapi/cli/php -r 'var_dump($a =array(&$a));'
Expected result:
----------------
2 and 3 as same result.
Actual result:
--------------
1:
array(1) {
[0]=>
NULL
}
2:
array(1) {
[0]=>
&NULL
}
3:
array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44128&edit=1