|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-03-09 18:13 UTC] abc at def dot ghi
Description:
------------
i use just build i downloaded from site (5.2.1) no exts, no optimizers.
it seem the $a,$b keep same internal pointer, this is quite serious error cos $b=$a should create separate array copy and it does but without the inner pointer.
if you replace $b=$a with $b=array(1,2,3); it works as expected
this was reported and ignored by someone on solaris before as well-- #40608
Reproduce code:
---------------
$a=array(1,2,3);
$b=$a;
foreach($a as $A)
{
foreach($b as $B)
{
echo "$A,$B\n";
break;
}
}
Expected result:
----------------
1,1
2,1
3,1
Actual result:
--------------
1,1
2,1
3,1
2,1
3,1
2,1
3,1
--infinite-
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 17 08:00:01 2025 UTC |
A quick fix for those that can't update, is to access the key in the inner loop: $a=array(1,2,3); $b=$a; foreach($a as $A) { foreach($b as $B) { key($b); echo "$A,$B\n"; break; } } Ouputs: 1,1 2,1 3,1