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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2020 The PHP Group
All rights reserved.
Last updated: Sun Nov 29 11:01:23 2020 UTC