#39477 [Bgs]: foreach iterators have global scope
| From: | phpbug dot 20 dot antialias at spamgourmet dot com | Date: | Sun, 12 Nov 2006 21:06:38 +0000 |
| Subject: | #39477 [Bgs]: foreach iterators have global scope | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-104865@lists.php.net to get a copy of this message | ||
ID: 39477
User updated by: phpbug dot 20 dot antialias at spamgourmet dot com
Reported By: phpbug dot 20 dot antialias at spamgourmet dot com
Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Mac OS X v. 10.4.8
PHP Version: 5.2.0
New Comment:
Alright... but I certianly wouldn't call this expected
behaviour, I also couldn't find mention of this in the
documentatinon.
Previous Comments:
------------------------------------------------------------------------
[2006-11-12 18:57:27] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
This is expected behaviour.
------------------------------------------------------------------------
[2006-11-12 11:26:34] phpbug dot 20 dot antialias at spamgourmet dot
com
Description:
------------
foreach iterators are bound to the scope of their arrays. This
causes problems when a global array has been partially
iterated through, and then inside the foreach, the same global
array is iterated through again. The the inner foreach
iterator effectively completes the iterations of the outer
foreach iterator, yielding unexpected results.
Reproduce code:
---------------
$t = array("1", "2");
global $t;
foreach($t as $a) {
foreach($t as $b) {
echo $b;
}
echo $a;
}
Expected result:
----------------
1212
Actual result:
--------------
121
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=39477&edit=1