#35084 [Opn->Fbk]: when using reference to array, then current() returns always first element
ID: 35084
Updated by: derick@php.net
Reported By: margus at zone dot ee
-Status: Open
+Status: Feedback
Bug Type: Scripting Engine problem
Operating System: SuSE 9.0
PHP Version: 4.4.1
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php4-STABLE-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php4-win32-STABLE-latest.zip
Previous Comments:
------------------------------------------------------------------------
[2005-11-03 11:57:04] margus at zone dot ee
OS is SuSE 9.0
------------------------------------------------------------------------
[2005-11-03 11:51:49] margus at zone dot ee
Description:
------------
I have reference to array and iterating through the array using
current()/next() loop
The problem is, that $element = current($arr_ref) returns always the
first element in array regardless of multiple next($arr_ref) calls
before current(...)
-----
It worked in php4.4.0. At the moment the only workaround is to replace
everywhere in code:
$element = current ($arr_ref)
to
$element = current(& $arr_ref);
Reproduce code:
---------------
$a = array('foot', 'bike');
reset ($a);
next($a);
echo "A:" . current ($a) . "<BR>";
$b =& $a;
reset ($b);
next($b);
echo "B:" . current ($b) . "<BR>";
Expected result:
----------------
A:bike
B:bike
Actual result:
--------------
A:bike
B:foot
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=35084&edit=1
Thread (4 messages)