#39477 [Opn->Bgs]: foreach iterators have global scope
| From: | tony2001@php.net | Date: | Sun, 12 Nov 2006 18:57:27 +0000 |
| Subject: | #39477 [Opn->Bgs]: foreach iterators have global scope | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-104858@lists.php.net to get a copy of this message | ||
ID: 39477
Updated by: tony2001@php.net
Reported By: phpbug dot 20 dot antialias at spamgourmet dot com
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Mac OS X v. 10.4.8
PHP Version: 5.2.0
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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