Bug #76231 [NEW]: while (list(x,y)=each(z)) fails after first loop

From: Date: Wed, 18 Apr 2018 00:34:01 +0000
Subject: Bug #76231 [NEW]: while (list(x,y)=each(z)) fails after first loop
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214783@lists.php.net to get a copy of this message
From: bmrgar at twc dot com Operating system: Linux PHP version: 7.2.4 Package: Arrays related Bug Type: Bug Bug description:while (list(x,y)=each(z)) fails after first loop Description: ------------ After iterating through a key,value array with a while loop, subsequent loops through the same data fail. Directly accessing array elements still works, as does cloning the array and looping through the new one (which will also fail after the first loop). Test script: --------------- $a = array("a"=>1,"b"=>2,"c"=>3); print "\"a\" = ".$a["a"]."\n"; print "\"b\" = ".$a["b"]."\n"; print "\"c\" = ".$a["c"]."\n\n"; print "First loop:\n"; while (list($key,$value) = each($a)) { print "Key: \"$key\" = Value: $value\n"; } print "\n"; print "Second loop:\n"; while (list($key,$value) = each($a)) { print "Key: \"$key\" = Value: $value\n"; } print "\n"; print "Third loop (after copy of 'a' to 'b':\n"; $b = $a; while (list($key,$value) = each($b)) { print "Key: \"$key\" = Value: $value\n"; } print "\n"; Expected result: ---------------- "a" = 1 "b" = 2 "c" = 3 First loop: Key: "a" = Value: 1 Key: "b" = Value: 2 Key: "c" = Value: 3 Second loop: Key: "a" = Value: 1 Key: "b" = Value: 2 Key: "c" = Value: 3 Third loop (after copy of 'a' to 'b': Key: "a" = Value: 1 Key: "b" = Value: 2 Key: "c" = Value: 3 Actual result: -------------- "a" = 1 "b" = 2 "c" = 3 First loop: Key: "a" = Value: 1 Key: "b" = Value: 2 Key: "c" = Value: 3 Second loop: Third loop (after copy of 'a' to 'b': Key: "a" = Value: 1 Key: "b" = Value: 2 Key: "c" = Value: 3 -- Edit bug report at https://bugs.php.net/bug.php?id=76231&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76231&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76231&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76231&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=76231&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=76231&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=76231&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=76231&r=needscript Try newer version: https://bugs.php.net/fix.php?id=76231&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=76231&r=support Expected behavior: https://bugs.php.net/fix.php?id=76231&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=76231&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=76231&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=76231&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76231&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=76231&r=dst IIS Stability: https://bugs.php.net/fix.php?id=76231&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=76231&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=76231&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=76231&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=76231&r=mysqlcfg

« previous php.bugs (#214783) next »