#49752 [Opn->Bgs]: reference maintained across different loops

From: Date: Sat, 03 Oct 2009 00:37:06 +0000
Subject: #49752 [Opn->Bgs]: reference maintained across different loops
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-143209@lists.php.net to get a copy of this message
ID: 49752 Updated by: rasmus@php.net Reported By: stevew at amainhobbies dot com -Status: Open +Status: Bogus Bug Type: Variables related Operating System: Win32 / Linux PHP Version: 5.2.11 New Comment: There is no reason the reference would be broken here. This is expected. Previous Comments: ------------------------------------------------------------------------ [2009-10-02 21:31:50] fa@php.net This has been like this since at least 5.1.6 (just tested) and also in 5.3.0. ------------------------------------------------------------------------ [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

« previous php.bugs (#143209) next »