|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-06-06 18:52 UTC] crrodriguez at suse dot de
[2008-07-06 11:56 UTC] jani@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 24 01:00:02 2025 UTC |
Description: ------------ When an static array if retourned from a method, for iterating, and acceded with the key() function, the reference pointer is moved to the end of the array. After the loop, the array is unaccessible. Important : if you add the following line : $tab = testbug::getTab(); before the loop, the error does not occur. you can use key(), current(), prev(), there is still a bug. First tested on windows 5.2.5 version, and still present on 5.2.6 version. There is no bug on 5.2.3 version. Thanks for answer. Reproduce code: --------------- <?php class testbug { static $tab = array( 'k1' => "elm1", 'k2' => "elm2", 'k3' => "elm3", 'k4' => "elm4", ); static function getTab() { return self::$tab; } } var_dump(testbug::getTab()); foreach (testbug::getTab() as $k => $v) { key(testbug::getTab()); } var_dump(testbug::getTab()); Expected result: ---------------- array 'k1' => string 'elm1' (length=4) 'k2' => string 'elm2' (length=4) 'k3' => string 'elm3' (length=4) 'k4' => string 'elm4' (length=4) array 'k1' => string 'elm1' (length=4) 'k2' => string 'elm2' (length=4) 'k3' => string 'elm3' (length=4) 'k4' => string 'elm4' (length=4) Actual result: -------------- array 'k1' => string 'elm1' (length=4) 'k2' => string 'elm2' (length=4) 'k3' => string 'elm3' (length=4) 'k4' => string 'elm4' (length=4) null