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:
Thanks for the note, but is there a way to out the iterator on the stack without copying the entire array? Previous Comments: ------------------------------------------------------------------------ [2006-11-12 21:24:48] [EMAIL PROTECTED] http://www.php.net/manual/en/control-structures.foreach.php The first form loops over the array given by array_expression. On each loop, the value of the current element is assigned to $value and ***the internal array pointer is advanced by one (so on the next loop, you'll be looking at the next element)***. ------------------------------------------------------------------------ [2006-11-12 21:06:38] phpbug dot 20 dot antialias at spamgourmet dot com Alright... but I certianly wouldn't call this expected behaviour, I also couldn't find mention of this in the documentatinon. ------------------------------------------------------------------------ [2006-11-12 18:57:27] [EMAIL PROTECTED] 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
