Bug #70387 [NEW]: Array corruption after iteration with a &pointer

From: Date: Sat, 29 Aug 2015 11:39:05 +0000
Subject: Bug #70387 [NEW]: Array corruption after iteration with a &pointer
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195630@lists.php.net to get a copy of this message
From: oleg dot nucer at gmail dot com Operating system: Windows 8.1 x64 PHP version: 5.6.12 Package: Scripting Engine problem Bug Type: Bug Bug description:Array corruption after iteration with a &pointer Description: ------------ I've found a realy strange bug .. Just look to the script and to the output! I've killed a half of our to understand what's going on in my script... After iterating over array with a pointer variable the array becomes corrupted for next time iteration... Look at the last element in foreach loop, it's the same with previous!! Test script: --------------- <? $sample = [ [ "first", 1 ], [ "second", 2 ], [ "third", 3 ] ]; foreach ( $sample AS &$s ) { } echo "Array: <pre>".print_r( $sample, 1 )."</pre><br/>"; foreach ( $sample AS $s ) { echo "Element: <pre>".print_r( $s, 1 )."</pre>"; } ?> Expected result: ---------------- Array: Array ( [0] => Array ( [0] => first [1] => 1 ) [1] => Array ( [0] => second [1] => 2 ) [2] => Array ( [0] => third [1] => 3 ) ) Element: Array ( [0] => first [1] => 1 ) Element: Array ( [0] => second [1] => 2 ) Element: Array ( [0] => third [1] => 3 ) Actual result: -------------- Array: Array ( [0] => Array ( [0] => first [1] => 1 ) [1] => Array ( [0] => second [1] => 2 ) [2] => Array ( [0] => third [1] => 3 ) ) Element: Array ( [0] => first [1] => 1 ) Element: Array ( [0] => second [1] => 2 ) Element: Array ( [0] => second [1] => 2 ) -- Edit bug report at https://bugs.php.net/bug.php?id=70387&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70387&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70387&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70387&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=70387&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=70387&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=70387&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=70387&r=needscript Try newer version: https://bugs.php.net/fix.php?id=70387&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=70387&r=support Expected behavior: https://bugs.php.net/fix.php?id=70387&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=70387&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=70387&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=70387&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70387&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=70387&r=dst IIS Stability: https://bugs.php.net/fix.php?id=70387&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=70387&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=70387&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=70387&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=70387&r=mysqlcfg

« previous php.bugs (#195630) next »