#35019 [NEW]: key() on array inside for loop returning wrong entry

From: Date: Sat, 29 Oct 2005 22:18:47 +0000
Subject: #35019 [NEW]: key() on array inside for loop returning wrong entry
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-87207@lists.php.net to get a copy of this message
From: pee at erkkila dot org Operating system: linux PHP version: 5.1.0RC4 PHP Bug Type: Arrays related Bug description: key() on array inside for loop returning wrong entry Description: ------------ Found a difference in mediawiki 1.5 with php4 vs php5. After tracking it down it looks like key() might be returning incorrect information inside a for loop. I might be missing a scope change someplace too though. This test case is based on Parser.php from that package. Reproduce code: --------------- <?php function one(&$state) { $state = array ( 'oneKey' => "oneValue", 'twoKey' => "twoValue", 'threeKey' => "threeValue", 'fourKey' => "fourValue", ); } function two(&$state) { for ( $contentDict = end( $state ); $contentDict !== false; $contentDict = prev( $state ) ) { print("Key:" . key($state) . "\n"); print("Value:" . $contentDict . "\n"); } } one($state); two($state); ?> Expected result: ---------------- Key:fourKey Value:fourValue Key:threeKey Value:threeValue Key:twoKey Value:twoValue Key:oneKey Value:oneValue Actual result: -------------- Key:oneKey Value:fourValue Key:oneKey Value:threeValue Key:oneKey Value:twoValue Key:oneKey Value:oneValue -- Edit bug report at http://bugs.php.net/?id=35019&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=35019&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=35019&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=35019&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=35019&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=35019&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=35019&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=35019&r=needscript Try newer version: http://bugs.php.net/fix.php?id=35019&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=35019&r=support Expected behavior: http://bugs.php.net/fix.php?id=35019&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=35019&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=35019&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=35019&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35019&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=35019&r=dst IIS Stability: http://bugs.php.net/fix.php?id=35019&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=35019&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=35019&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=35019&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=35019&r=mysqlcfg

« previous php.bugs (#87207) next »