#28734 [Com]: Operator = changes structure of self-referencing arrays

From: Date: Fri, 11 Jun 2004 17:40:25 +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-60799@lists.php.net to get a copy of this message
ID: 28734 Comment by: imprestavel at gameguru dot com dot br 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: Tested PHP 5.0.0 RC3 and latest build (200406111430) under Windows2000 and had the same problem Previous Comments: ------------------------------------------------------------------------ [2004-06-11 09:38:37] tomas_matousek at hotmail dot com Don't know how that is possible in your version of PHP 5.0.0 RC3, but in mine (I'm testing RC3 available on www.php.net not the latest version from CVS) the bug is still there (result is the same as I described in "Actual Result"). ------------------------------------------------------------------------ [2004-06-11 01:43:58] D dot Kingma at jool dot nl 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 ------------------------------------------------------------------------ [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

« previous php.bugs (#60799) next »