bug when using foreach with references?
| From: | Richard K Miller | Date: | Thu, 22 Oct 2009 01:37:02 +0000 |
| Subject: | bug when using foreach with references? | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-45862@lists.php.net to get a copy of this message | ||
Is this a bug in PHP?
<?php
$items = array('apple', 'banana', 'carrot');
print_r($items);
foreach ($items as &$item) { }
print_r($items);
foreach ($items as $item) { }
print_r($items);
?>
// Output:
Array
(
[0] => apple
[1] => banana
[2] => carrot
)
Array
(
[0] => apple
[1] => banana
[2] => carrot
)
Array
(
[0] => apple
[1] => banana
[2] => banana
)
Two bananas in the last set?! Not what I expected.
Richard