From: ugo at iliona dot net Operating system: Linux/BSD PHP version: 5.2.0 PHP Bug Type: Arrays related Bug description: Problem with foreach and referenced values
Description: ------------ Hello, This bug was tried on multiple Unix versions and multiple processors (32/64bits), and multiple PHP5 versions (including 5.2.0), so it seems really to be on the side of PHP. After using a foreach with a referenced value, and then another foreach (without the referenced value), the original array is broken. Apparently, the last value of the array takes the value of the n - 1 last value. I've reduced the problem to its simplest form and attached it to this bug report. Greeting, Ugo PARSI Reproduce code: --------------- <?php $arr = array(1, 2, 3, 4); foreach ($arr as &$value) { $value = $value * 2; } print_r($arr); foreach ($arr as $value) { $value = $value; } print_r($arr); ?> Expected result: ---------------- Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 8 ) Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 8 ) Actual result: -------------- Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 8 ) Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 6 ) -- Edit bug report at http://bugs.php.net/?id=40065&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40065&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40065&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40065&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=40065&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=40065&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=40065&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=40065&r=needscript Try newer version: http://bugs.php.net/fix.php?id=40065&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=40065&r=support Expected behavior: http://bugs.php.net/fix.php?id=40065&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=40065&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=40065&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=40065&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40065&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=40065&r=dst IIS Stability: http://bugs.php.net/fix.php?id=40065&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=40065&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=40065&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=40065&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=40065&r=mysqlcfg