|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-01-07 08:53 UTC] lgynove at 163 dot com
Description:
------------
n/a
Test script:
---------------
$array = array(1);
while(list($k, $v) = each($array))
{
foreach($array as $v2)
{
$array[$k] = 2;
echo $array[$k];
}
}
Expected result:
----------------
2
Actual result:
--------------
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
Endless cycle
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 23:00:02 2025 UTC |
This is a corner case. When you do the write in the array, you're forcing a separation of the variable array. Because it's separated, its internal pointer is reset. This is a simpler test case: <?php function force_sep(&$v) {} $a = array(1); next($a); var_dump(current($a)); $b = $a; //refcount == 2 force_sep($a); var_dump(current($a)); Output: bool(false) int(1) //internal pointer was reset! The call to force_sep is actually unnecessary because current() takes its parameter by reference, forcing a separation on its own. The fix here would be to reproduce the array internal pointer of the old zval in the new zval upon separation, but that has a performance cost that I don't think is warranted.