ID: 40705
Comment by: jamesgauth at gmail dot com
Reported By: [EMAIL PROTECTED]
Status: Assigned
Bug Type: Arrays related
Operating System: Irrelevant
PHP Version: 5.2.1
Assigned To: dmitry
New Comment:
This problem occurs in copies of an object's properties too. The array
pointer is advanced by foreach in both the original and the copied
variable.
<?php
class foo {
var $arr = array(1, 2, 3);
function test() {
var_dump(key($this->arr));
$array_copy = $this->arr;
foreach ($array_copy as $val) {}
}
}
$a = new foo();
$a->test();
$a->test();
?>
Previous Comments:
------------------------------------------------------------------------
[2007-03-19 19:59:31] [EMAIL PROTECTED]
Tested this example against the 5.2.1 zipfile from php.net on WinXP and
the problem does occur.
Also tested it against the 5.2 snapshot (php5.2-win32-200703191630.zip)
from php.net, on WinXP, and the problem seems to still exist.
------------------------------------------------------------------------
[2007-03-06 13:19:09] [EMAIL PROTECTED]
The same as http://bugs.php.net/bug.php?id=40509
------------------------------------------------------------------------
[2007-03-03 12:31:20] [EMAIL PROTECTED]
Description:
------------
If an array is passed by value to the function and is iterated over
within said function, the "internal pointer" of the original array is
moved.
Reproduce code:
---------------
function doForeach($array)
{
foreach ($array as $k => $v) {
// do stuff
}
}
$foo = array('foo', 'bar', 'baz');
doForeach($foo);
var_dump(key($foo));
Expected result:
----------------
int(0) (returned by versions prior to 5.2.1)
Actual result:
--------------
NULL (returned by version 5.2.1 and current 5.2 snapshot)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40705&edit=1