ID: 49752
Updated by: [email protected]
Reported By: stevew at amainhobbies dot com
Status: Open
Bug Type: Variables related
Operating System: Win32 / Linux
PHP Version: 5.2.11
New Comment:
This has been like this since at least 5.1.6 (just tested) and also in
5.3.0.
Previous Comments:
------------------------------------------------------------------------
[2009-10-02 18:24:18] stevew at amainhobbies dot com
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 this bug report at http://bugs.php.net/?id=49752&edit=1