From: php dot net dot 1 at odi dot ch Operating system: Win32 PHP version: 4.3.3 PHP Bug Type: Arrays related Bug description: foreach scope modality
Description: ------------ The behaviour of foreach seems to be scope dependent. The following code (slightly more than 20 lines) should yield the same results in both cases, but doesn't. I know that foreach uses the internal array pointer. The result beeing "de" or "de fr it" is NOT the topic here. The point is that the two results differ, although the code is the same except for the scope. This could be the reason for bug #19285 Reproduce code: --------------- <?php $usr_langs = array('de', 'fr', 'it'); function f() { global $usr_langs; foreach($usr_langs as $lang) { # do something } } function g() { global $usr_langs; foreach ($usr_langs as $lang) { f(); echo "$lang "; } } echo "Test1:<br>"; g(); echo "<br>----------<br>"; echo "Test2:<br>"; foreach ($usr_langs as $lang) { f(); echo "$lang "; } ?> Expected result: ---------------- Test1: de ---------- Test2: de OR even better Test1: de fr it ---------- Test2: de fr it Actual result: -------------- Test1: de ---------- Test2: de fr it -- Edit bug report at http://bugs.php.net/?id=26396&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26396&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26396&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=26396&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=26396&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=26396&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=26396&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=26396&r=support Expected behavior: http://bugs.php.net/fix.php?id=26396&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=26396&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=26396&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=26396&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26396&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=26396&r=dst IIS Stability: http://bugs.php.net/fix.php?id=26396&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=26396&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=26396&r=float