#48875 [Com]: unexpected foreach behavior with references, 2 foreaches, and same value var
| From: | stepheneliotdewey at gmail dot com | Date: | Fri, 10 Jul 2009 00:40:58 +0000 |
| Subject: | #48875 [Com]: unexpected foreach behavior with references, 2 foreaches, and same value var | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-139560@lists.php.net to get a copy of this message | ||
ID: 48875
Comment by: stepheneliotdewey at gmail dot com
Reported By: stepheneliotdewey at gmail dot com
Status: Open
Bug Type: Scripting Engine problem
Operating System: Vista 64-bit
PHP Version: 5.2.10
New Comment:
I should note that I first saw this bug in a comment posted earlier
today in the documentation:
http://us3.php.net/manual/en/control-structures.foreach.php#92116
Previous Comments:
------------------------------------------------------------------------
[2009-07-10 00:36:21] stepheneliotdewey at gmail dot com
Description:
------------
If you look at the final print-out for the below, it will print a, b,
b, instead of the expected a, b, c. I don't think this is the expected
behavior.
Reproduce code:
---------------
<?php
$a = array('a', 'b','c');
foreach($a as &$row){
//you don't have to do anything here
}
print_r($a);
foreach($a as $row){
echo "<br />".$row;
}
?>
Expected result:
----------------
a
b
c
Actual result:
--------------
a
b
b
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48875&edit=1