|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-08-30 23:24 UTC] mark at lange dot demon dot co dot uk
[2015-08-30 23:45 UTC] rasmus@php.net
-Status: Open
+Status: Not a bug
[2015-08-30 23:45 UTC] rasmus@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 10:00:01 2025 UTC |
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 )