From: stevew at amainhobbies dot com Operating system: Win32 / Linux PHP version: 5.2.11 PHP Bug Type: Variables related Bug description: reference maintained across different loops
Description: ------------ I don't expect the $total in the second foreach to still be a reference to the last item from the previous foreach. Reproduce code: --------------- <?php $totals = array(array('class' => 'Foo', 'value' => '1'), array('class' => 'Test', 'value' => '2'), array('class' => 'Bar', 'value' => '3')); foreach ($totals as &$total) { switch ($total['class']) { case 'Test': $total['value'] *= 2; break; default: break; } } foreach ($totals as $total) { echo $total['class'] . ' : ' . $total['value'] . "\n"; } ?> Expected result: ---------------- Foo : 1 Test : 4 Bar : 3 Actual result: -------------- Foo : 1 Test : 4 Test : 4 -- Edit bug report at http://bugs.php.net/?id=49752&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49752&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49752&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49752&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49752&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49752&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49752&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49752&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49752&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49752&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49752&r=support Expected behavior: http://bugs.php.net/fix.php?id=49752&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49752&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49752&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49752&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49752&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49752&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49752&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49752&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49752&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49752&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49752&r=mysqlcfg