ID:               40065
 User updated by:  ugo at iliona dot net
 Reported By:      ugo at iliona dot net
 Status:           Bogus
 Bug Type:         Arrays related
 Operating System: Linux/BSD
 PHP Version:      5.2.0
 New Comment:

Ok, I see... it's quite logical if foreach behave like this....sorry
for the bogus report then...
But, since it's not a bug, that's a hell of nice weird feature :/

It should probably be put in the documentation that foreach doesn't
unset/reset it's value(s) variable(s) (since it does this for the it's
array pointer, and some languages does this too, it's quite an
unpredictable situation)

Thanks anyway and sorry for this report, 

Ugo


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

[2007-01-08 18:10:55] [EMAIL PROTECTED]

#29992 and it is not a bug.

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

[2007-01-08 18:06:52] ugo at iliona dot net

Hmmm...
I haven't found a similar open bug in the database (I wouldn't have
posted it otherwise), but if you say that it is the same as another
one, that's okay for me as long as it is fixed in the next version :)

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

[2007-01-08 17:55:24] [EMAIL PROTECTED]

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.

,

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

[2007-01-08 17:42:34] ugo at iliona dot net

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 this bug report at http://bugs.php.net/?id=40065&edit=1

Reply via email to