php.net |  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
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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


 [2013-01-07 10:30 UTC] cataphract@php.net
-Status: Open +Status: Not a bug
 [2013-01-08 10:58 UTC] cataphract@php.net
-Summary: n/a +Summary: Internal pointer reset on separation
 [2013-01-08 10:58 UTC] cataphract@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 10:01:26 2024 UTC