#48137 [Bgs]: assigning array element reference appears to modify array
| From: | scottmac@php.net | Date: | Mon, 04 May 2009 00:34:30 +0000 |
| Subject: | #48137 [Bgs]: assigning array element reference appears to modify array | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-136703@lists.php.net to get a copy of this message | ||
ID: 48137
Updated by: scottmac@php.net
Reported By: mike at clove dot com
Status: Bogus
Bug Type: Arrays related
Operating System: Mac OS X 10.5.6
PHP Version: 5.2.9
New Comment:
References aren't pointers, all they say is that the two values should
point to the same content. This is still the case even if the array was
changed.
http://www.php.net/manual/en/language.references.whatare.php
Previous Comments:
------------------------------------------------------------------------
[2009-05-03 17:04:57] derick@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
Nah, this is fine. It doesn\'t modify the array. The & just shows that
the is_ref bit on the zval container that contains the int(1) value is
set.
------------------------------------------------------------------------
[2009-05-03 17:01:04] mike at clove dot com
Description:
------------
Assigning reference to an array element appears to modify the
array element rather than simply creating a reference to it.
This is surprising, to say the least.
At least I think this is a bug and couldn't find anything with the same
behavior and such minimal code.
Reproduce code:
---------------
$a = array(1,2);
$r =& $a[0];
var_dump($a);
Expected result:
----------------
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
Actual result:
--------------
array(2) {
[0]=>
&int(1)
[1]=>
int(2)
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48137&edit=1