|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63926 Internal pointer reset on separation
Submitted: 2013-01-07 08:53 UTC Modified: 2013-01-08 10:58 UTC
From: lgynove at 163 dot com Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 5.4.10 OS: windows xp
Private report: No CVE-ID: None
 [2013-01-07 08:53 UTC] lgynove at 163 dot com

Test script:
$array = array(1);
while(list($k, $v) = each($array))
	foreach($array as $v2)
		$array[$k] = 2;
		echo $array[$k];

Expected result:

Actual result:
Endless cycle


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-07 10:30 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

 [2013-01-07 10:30 UTC]
-Status: Open +Status: Not a bug
 [2013-01-08 10:58 UTC]
-Summary: n/a +Summary: Internal pointer reset on separation
 [2013-01-08 10:58 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:

function force_sep(&$v) {}

$a = array(1);
$b = $a; //refcount == 2

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.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 10:01:28 2024 UTC