ID: 41372
User updated by: forjest at gmail dot com
Reported By: forjest at gmail dot com
Status: Open
Bug Type: Arrays related
Operating System: WinXP, Linux
PHP Version: 4.4.7
New Comment:
/*for simple case just wrap array in some array function. That will
cause small overhead, but at least save your internal pointer*/
$Foo = array('val1', 'val2', 'val3');
end($Foo);
var_dump(key($Foo));
$AllOkay = array_merge($Foo);
var_dump(key($Foo));
----------
/*But to make immune running context for error handler function nothing
helps, except ugly serialize/unserialize solution*/
error_reporting(E_ALL);
function TestErrorHandler($severity, $message, $filename, $line,
$super_globals)
{
global $foo;
$foo = unserialize(serialize($super_globals));
}
class Test
{
function run()
{
$Res = array('val1', 'val2', 'val3');
end($Res);
var_dump(key($Res));
HEY;//raise notice error
var_dump(key($Res));
}
}
$test = new Test();
set_error_handler('TestErrorHandler');
$test-> run();
Previous Comments:
------------------------------------------------------------------------
[2007-05-12 08:32:17] forjest at gmail dot com
Description:
------------
Bug first appeared in 4.4.2. Version 4.4.1 works okay.
5.1.4, 5.2.1 has this bug too.
-----
Seems algorithm of array copying was changed at 4.4.2 and 5.1.2
versions.
-----
This behavior cause problems in unexpected situations such as error
handling functions, when array pointer reseted due copying from another
array which reference to it.
Reproduce code:
---------------
$Foo = array('val1', 'val2', 'val3');
end($Foo);
var_dump(key($Foo));
$MagicInternalPointerResetter = $Foo;
var_dump(key($Foo));
--
Code describing unexpected results of this behavior listed here:
http://www.pastebin.ru/10226
Expected result:
----------------
int(2) int(2)
Actual result:
--------------
int(2) int(0)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41372&edit=1