Bug #70510 [NEW]: Variables defined by a cycle are not isolated and cause side effects

From: Date: Wed, 16 Sep 2015 10:28:58 +0000
Subject: Bug #70510 [NEW]: Variables defined by a cycle are not isolated and cause side effects
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196035@lists.php.net to get a copy of this message
From: mumu at seznam dot cz Operating system: Windows PHP version: 7.0.0RC2 Package: Variables related Bug Type: Bug Bug description:Variables defined by a cycle are not isolated and cause side effects Description: ------------ The first cycle has $item defined by reference. The second by value. The $item keeps being a reference to the (last item of the) array even it is used as by value inside the second cycle. As such, the two cycles are not properly isolated as would have been expected. Test script: --------------- <?php $list = array( 'a' => 'x', 'b' => 'y', 'c' => 'z', ); foreach ($list as &$item) { $item .= $item; } foreach ($list as $key => $item) { echo $key . ': ' . $item . "\n"; } ?> Expected result: ---------------- a: xx b: yy c: zz Actual result: -------------- a: xx b: yy c: yy -- Edit bug report at https://bugs.php.net/bug.php?id=70510&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70510&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70510&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70510&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=70510&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=70510&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=70510&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=70510&r=needscript Try newer version: https://bugs.php.net/fix.php?id=70510&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=70510&r=support Expected behavior: https://bugs.php.net/fix.php?id=70510&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=70510&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=70510&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=70510&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70510&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=70510&r=dst IIS Stability: https://bugs.php.net/fix.php?id=70510&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=70510&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=70510&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=70510&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=70510&r=mysqlcfg

« previous php.bugs (#196035) next »