Bug #68215 [NEW]: Behavior of foreach has changed

From: Date: Mon, 13 Oct 2014 03:13:07 +0000
Subject: Bug #68215 [NEW]: Behavior of foreach has changed
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188045@lists.php.net to get a copy of this message
From: pegasus at vaultwiki dot org Operating system: Centos 6 64-bit PHP version: master-Git-2014-10-13 (Git) Package: Scripting Engine problem Bug Type: Bug Bug description:Behavior of foreach has changed Description: ------------ Historically, foreach ($arr AS $val) has acted on a copy of $arr, in order to prevent issues if $arr entries are modified after the loop has already begun iterating. If the current value was desired, historically for or while loops were used instead. However, in Master, it appears that $arr always refers to the current value of $arr. This is in contradiction to the historical behavior. If entries are added inside the loop, foreach will keep going for the new entries. If existing entries are otherwise modified, the $val corresponds to the updated entry rather than the $val when the loop began. -- Edit bug report at https://bugs.php.net/bug.php?id=68215&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68215&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68215&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68215&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=68215&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=68215&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=68215&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=68215&r=needscript Try newer version: https://bugs.php.net/fix.php?id=68215&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=68215&r=support Expected behavior: https://bugs.php.net/fix.php?id=68215&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=68215&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=68215&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=68215&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68215&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=68215&r=dst IIS Stability: https://bugs.php.net/fix.php?id=68215&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=68215&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=68215&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=68215&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=68215&r=mysqlcfg

« previous php.bugs (#188045) next »