#40385 [Opn->Bgs]: inserting references to an array
| From: | tony2001@php.net | Date: | Wed, 07 Feb 2007 12:45:11 +0000 |
| Subject: | #40385 [Opn->Bgs]: inserting references to an array | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-108542@lists.php.net to get a copy of this message | ||
ID: 40385
Updated by: tony2001@php.net
Reported By: viqq at gazeta dot pl
-Status: Open
+Status: Bogus
Bug Type: Variables related
Operating System: Linux ubuntu 2.6.15-27-386
PHP Version: 5.2.0
New Comment:
>$t[] = &$node
"$t[0] and $node both point to the same value".
>$node = '2';
"$node is changed to '2', $t[0] is changed either".
>$t[] = &$node;
"$t[1] points to the value already referenced by $node and $t[0]".
Previous Comments:
------------------------------------------------------------------------
[2007-02-07 12:39:15] viqq at gazeta dot pl
Description:
------------
When a reference to a variable (containing e.g. a literal or an object)
is inserted into an array, all existing references in this array becomes
references to this variable.
Reproduce code:
---------------
$t = NULL;
$node = '1';
// or $node = new Object();
$t[] = &$node;
$node = '2';
// or $node = new Object();
$t[] = &$node;
var_dump($t);
Expected result:
----------------
array(2) {
[0]=>
&string(1) "1"
[1]=>
&string(1) "2"
}
Actual result:
--------------
array(2) {
[0]=>
&string(1) "2"
[1]=>
&string(1) "2"
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40385&edit=1