From: anshul at designgrill dot com Operating system: All PHP version: 5.2.10 PHP Bug Type: Arrays related Bug description: Incorrect array assignment
Description: ------------ If you keep reference to an element of the array before the copy operation using = operator, you can still modify both the arrays using the reference copied earlier. The same doesn't happen if you keep the reference after the copy operation and try to modify the variable using it. Reproduce code: --------------- <?php $arr1 = array(1, 2); $var = &$arr1[0];//Keeping the reference $arr2 = $arr1;//Copy operation $var = 10;//Will modify both the arrays, bad print_r($arr1); print_r($arr2); ?> Expected result: ---------------- Array ( [0] => 10 [1] => 2 ) Array ( [0] => 1 [1] => 2 ) Actual result: -------------- Array ( [0] => 10 [1] => 2 ) Array ( [0] => 10 [1] => 2 ) -- Edit bug report at http://bugs.php.net/?id=49322&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49322&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49322&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49322&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49322&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49322&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49322&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49322&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49322&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49322&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49322&r=support Expected behavior: http://bugs.php.net/fix.php?id=49322&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49322&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49322&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49322&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49322&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49322&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49322&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49322&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49322&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49322&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49322&r=mysqlcfg