#28734 [Com]: Operator = changes structure of self-referencing arrays
| From: | D dot Kingma at jool dot nl | Date: | Thu, 10 Jun 2004 23:43:59 +0000 |
| Subject: | #28734 [Com]: Operator = changes structure of self-referencing arrays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-60759@lists.php.net to get a copy of this message | ||
ID: 28734
Comment by: D dot Kingma at jool dot nl
Reported By: tomas_matousek at hotmail dot com
Status: Open
Bug Type: Scripting Engine problem
Operating System: WinXP
PHP Version: 5.0.0RC2
New Comment:
Results on RC3:
Array
(
[0] => 1
[1] => Z
[2] => 3
[3] => 4
[4] => Array
(
[0] => 1
[1] => Z
[2] => 3
[3] => 4
[4] => Array
*RECURSION*
)
)
Seems as aspected results
Previous Comments:
------------------------------------------------------------------------
[2004-06-10 20:46:39] tomas_matousek at hotmail dot com
Description:
------------
Create an array $b and set some of its item to reference the array
itself by =& operator. Then assign this array to some other variable.
This assignment (*) makes something wrong in the array $b because if
you change $b's items after this assignment the structure of array $b
is changed.
However, if that assignment (*) doesn't take place the behavior is
correct.
Reproduce code:
---------------
$b = array(1,2,3,4);
$b[4] =& $b;
// this assignment probably makes changes to $b's structure
$c = $b;
$b[1] = 'X';
$b[4][1] = 'Y';
$b[4][4][1] = 'Z';
print_r($b);
Expected result:
----------------
Array
(
[0] => 1
[1] => Z
[2] => 3
[3] => 4
[4] => Array
*RECURSION*
)
Actual result:
--------------
Array
(
[0] => 1
[1] => X
[2] => 3
[3] => 4
[4] => Array
(
[0] => 1
[1] => Y
[2] => 3
[3] => 4
[4] => Array
(
[0] => 1
[1] => Z
[2] => 3
[3] => 4
[4] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => Array
*RECURSION*
)
)
)
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=28734&edit=1