#48137 [Bgs]: assigning array element reference appears to modify array
ID: 48137
User updated by: mike at clove dot com
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:
Thanks derick at php dot net.
It's confusing to have var_dump() tell me that the assignment has
changed element 0 from a value to a reference. That seems to me to be a
bug in var_dump(): in the code, $r is the reference, not $a[0] - which
should still be a value. I think this means var_dump() is displaying
unreliable information.
to scottmac at php dot net: the issue isn't what a reference is, it's
that the a := b appears to be changing the value of 'b', which is just
plain wrong for any assignment in any programming language I know
[unless $a =& $b; $a = $b; which would be specifically asking to do
this].
Previous Comments:
------------------------------------------------------------------------
[2009-05-04 00:34:29] scottmac@php.net
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
------------------------------------------------------------------------
[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
Thread (4 messages)