php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35084 when using reference to array, then current() returns always first element
Submitted: 2005-11-03 11:51 UTC Modified: 2005-11-03 12:15 UTC
From: margus at zone dot ee Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.4.1 OS: SuSE 9.0
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: margus at zone dot ee
New email:
PHP Version: OS:

 

 [2005-11-03 11:51 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-03 11:57 UTC] margus at zone dot ee
OS is SuSE 9.0
 [2005-11-03 12:16 UTC] margus at zone dot ee
yes, CVS snapshot (php4-STABLE-200511030951) is working
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 16:01:29 2024 UTC