ID:               36240
 Updated by:       [EMAIL PROTECTED]
 Reported By:      dshadow at zort dot net
-Status:           Open
+Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Mac OS X
 PHP Version:      5.1.2
 New Comment:

Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Duplicate of bug #29992


Previous Comments:
------------------------------------------------------------------------

[2006-02-01 08:20:39] judas dot iscariote at gmail dot com

BOGUS.
read  bug 29992

------------------------------------------------------------------------

[2006-02-01 06:35:00] dshadow at zort dot net

Description:
------------
After using foreach($arr as $k => &$v) to modify the $arr, 
iterating again using the same variable $v causes the array to 
be altered unexpectedly.

Adding an unset($v) between the two foreach loops, or using a 
different variable on the second foreach loop works around the 
problem.

Reproduce code:
---------------
<?

$arr = array(
        'one' => 1,
        'two' => 2,
        'three' => 3,
);

foreach($arr as $k => &$v)
        if($v == 1)
                $v = 'meh';

print_r($arr);

foreach($arr as $k => $v)
        ;

print_r($arr);


Expected result:
----------------
The code above should not cause the $arr to be modified by 
running the second foreach loop.

Actual result:
--------------
The code above outputs the following:

Array ( [one] => meh [two] => 2 [three] => 3 )
Array ( [one] => meh [two] => 2 [three] => 2 )



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=36240&edit=1

Reply via email to