From: shustrik at softech dot lv Operating system: Linux 2.4.20 PHP version: 4.3.10 PHP Bug Type: Zend Engine 2 problem Bug description: foreach behaviour change in 4.3.10
Description: ------------ Apparently, the foreach loop such as "foreach ($array as $value)" puts some kind of index-value array into $value. This differs from what the documentation says and does not seem to appear in changelog or make any sense. The code below produces different results on 4.3.9 and 4.3.10 Reproduce code: --------------- <?php $a = array( 'ab' => array( 'a' => 1, 'b' => 2 ), 'cd' => array( 'c' => 3, 'd' => 4 ) ); foreach ($a as $key => $array) { echo '<br />key ' . $key . ', array: '; var_dump($array); foreach ($array as $datafield) { echo '<br />key ' . $key . ', subarray element: '; var_dump($datafield); } } ?> Expected result: ---------------- PHP 4.3.9: key ab, array: Array ( [a] => 1 [b] => 2 ) key ab, subarray element: 1 key ab, subarray element: 2 key cd, array: Array ( [c] => 3 [d] => 4 ) key cd, subarray element: 3 key cd, subarray element: 4 Actual result: -------------- PHP 4.3.10: key ab, array: Array ( [a] => 1 [b] => 2 ) key ab, subarray element: Array ( [0] => 1 [1] => a ) key ab, subarray element: Array ( [0] => 2 [1] => b ) key cd, array: Array ( [c] => 3 [d] => 4 ) key cd, subarray element: Array ( [0] => 3 [1] => c ) key cd, subarray element: Array ( [0] => 4 [1] => d ) -- Edit bug report at http://bugs.php.net/?id=31181&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31181&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31181&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31181&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=31181&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=31181&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=31181&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=31181&r=needscript Try newer version: http://bugs.php.net/fix.php?id=31181&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=31181&r=support Expected behavior: http://bugs.php.net/fix.php?id=31181&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=31181&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=31181&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=31181&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31181&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=31181&r=dst IIS Stability: http://bugs.php.net/fix.php?id=31181&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=31181&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=31181&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=31181&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=31181&r=mysqlcfg