Friday, August 28, 2009

PHP Pitfalls: An array's pointer is reset when copied

Array's pointers are reset when the original array is logically copied and thus has 2+ reference counts internally. This doesn't happen if it is not logically copied.

$a = array("one", "two");
next($a);
var_dump(current($a)); //=> "two"
$b = $a;
var_dump(current($a)); // => "one"
?>

No comments: