From: kdmtr at yahoo dot com Operating system: Win32, Unix PHP version: 5.1.2 PHP Bug Type: Feature/Change Request Bug description: foreach strange behaviour
Description: ------------ foreach seems to run in different ways when called globally and from a function. As it can be understood from the documentation, foreach shouldn't touch an original array and operate with its copy instead. But at least, one could expect its behaviour to be similar for the 2 cases described in code. Reproduce code: --------------- $array = array(1, 2); function test() { global $array; foreach ($array as $a) foreach ($array as $b) echo "$a $b\n"; } foreach ($array as $a) foreach ($array as $b) echo "$a $b\n"; echo "---\n"; test(); Expected result: ---------------- 1 1 1 2 2 1 2 2 --- 1 1 1 2 2 1 2 2 Actual result: -------------- 1 1 1 2 2 1 2 2 --- 1 1 1 2 -- Edit bug report at http://bugs.php.net/?id=36070&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36070&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36070&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36070&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=36070&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=36070&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=36070&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=36070&r=needscript Try newer version: http://bugs.php.net/fix.php?id=36070&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=36070&r=support Expected behavior: http://bugs.php.net/fix.php?id=36070&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=36070&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=36070&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=36070&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36070&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=36070&r=dst IIS Stability: http://bugs.php.net/fix.php?id=36070&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=36070&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=36070&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=36070&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=36070&r=mysqlcfg