#33572 [NEW]: Behavior of foreach changed

From: Date: Tue, 05 Jul 2005 08:00:26 +0000
Subject: #33572 [NEW]: Behavior of foreach changed
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-81390@lists.php.net to get a copy of this message
From: daniel at bokko dot nl Operating system: Gentoo linux 2.4.22 PHP version: 4.3.11 PHP Bug Type: Arrays related Bug description: Behavior of foreach changed Description: ------------ After updrade to php 4.3.11 (from 4.3.4) the behaviour of foreach changed. When i do not specify a $key in the foreach statement, the value is wrong when it's an array. Reproduce code: --------------- <pre> <?php $array = array(); $array[0] = array('apple', 'banana', 'pear', 'grape'); $array[1] = array('apple', 'banana', 'pear', 'grape'); print_r($array); echo "\n-----------------\n"; foreach($array AS $v) { print_r($v); } ?> </pre> Expected result: ---------------- Array ( [0] => apple [1] => banana [2] => pear [3] => grape ) Array ( [0] => apple [1] => banana [2] => pear [3] => grape ) Actual result: -------------- Array ( [0] => Array ( [0] => apple [1] => banana [2] => pear [3] => grape ) [1] => 0 ) Array ( [0] => Array ( [0] => apple [1] => banana [2] => pear [3] => grape ) [1] => 1 ) -- Edit bug report at http://bugs.php.net/?id=33572&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33572&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33572&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33572&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=33572&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=33572&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=33572&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=33572&r=needscript Try newer version: http://bugs.php.net/fix.php?id=33572&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=33572&r=support Expected behavior: http://bugs.php.net/fix.php?id=33572&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=33572&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=33572&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=33572&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33572&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=33572&r=dst IIS Stability: http://bugs.php.net/fix.php?id=33572&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=33572&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=33572&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=33572&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=33572&r=mysqlcfg

« previous php.bugs (#81390) next »