[UPHPU] buggy behavior with two foreach loops
Richard K Miller
richardkmiller at gmail.com
Tue Oct 20 01:56:24 MDT 2009
On Oct 20, 2009, at 12:10 AM, Richard K Miller wrote:
> Is this a bug in PHP?
>
These reports describe the issue (though more verbosely):
http://bugs.php.net/bug.php?id=29992
http://bugs.php.net/bug.php?id=31118
http://bugs.php.net/bug.php?id=31125
http://bugs.php.net/bug.php?id=36240
Seems odd for Derick and Andi to disregard this as "expected
behavior". The fix is to unset() the iterator value before the second
foreach loop. (Why should that be necessary?)
<?php
$items = array('apple', 'banana', 'carrot');
print_r($items);
foreach ($items as &$item) { }
print_r($items);
unset ($item); // required
foreach ($items as $item) { }
print_r($items);
More information about the UPHPU
mailing list