#40050 [Bgs]: Array assignment without references
ID: 40050
User updated by: BenBE at omorphia dot de
Reported By: BenBE at omorphia dot de
Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Windows 2K
PHP Version: 5.2.0
New Comment:
Please quote in detail the page of the manual you are referring to, as
I can't find any reason why assigning an array with = should create
such a weird pointer structure.
As mentioned below the =& assignment is right, only the = assignment is
in question (and most likely wrong IMHO).
Previous Comments:
------------------------------------------------------------------------
[2007-01-07 21:58:01] iliaa@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
.
------------------------------------------------------------------------
[2007-01-07 19:57:47] BenBE at omorphia dot de
Description:
------------
When assigning an array by-value into itself PHP will insert a
self-referencing Array into the new entry
Reproduce code:
---------------
$a = array();
$a[] =& $a;
print_r($a);
$b = array();
$b[] = $b;
print_r($b);
Expected result:
----------------
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
*RECURSION*
}
}
}
array(1) {
[0]=>
array(0) {
}
}
$b[0] should contain an empty array because $b was assigned by-value,
i.e. should get copied.
Actual result:
--------------
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
*RECURSION*
}
}
}
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
*RECURSION*
}
}
}
Comparing the references (see my entry regarding Spotting References)
you find that $b and $b[0] are different pointers and $b[0] is an array
like the one created in $a.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40050&edit=1
Thread (4 messages)