php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35444 Functions next/prev don't change array pointer on global array in function
Submitted: 2005-11-28 13:16 UTC Modified: 2005-11-28 13:28 UTC
From: gentoo at slave dot umbr dot cas dot cz Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.4.1 OS: Linux Fedora Core 2
Private report: No CVE-ID: None
 [2005-11-28 13:16 UTC] gentoo at slave dot umbr dot cas dot cz
Description:
------------
If you have user defined function and this function uses global array (using global $ARRAY;), you cannot use functions next()/prev(), because they do not change internal array pointer.

Reproduce code:
---------------
$msort=array();

function do_print_test() {
        global $msort;
        reset($msort);echo sprintf("0:%s=%s\n",key($msort),current($msort));
        next($msort);echo sprintf("1:%s=%s\n",key($msort),current($msort));
        next($msort);echo sprintf("2:%s=%s\n",key($msort),current($msort));
        next($msort);echo sprintf("3:%s=%s\n",key($msort),current($msort));
        next($msort);echo sprintf("4:%s=%s\n",key($msort),current($msort));
}

array_push($msort,"a");
array_push($msort,"b");
array_push($msort,"c");
array_push($msort,"d");
array_push($msort,"e");
array_push($msort,"f");

do_print_test();


Expected result:
----------------
in PHP 4.3.9 and 4.4.0

0:0=a
1:1=b
2:2=c
3:3=d
4:4=e


Actual result:
--------------
in PHP 4.4.1

0:0=a
1:0=a
2:0=a
3:0=a
4:0=a


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-28 13:17 UTC] tony2001@php.net
Fixed in CVS about a month ago.
 [2005-11-28 13:19 UTC] gentoo at slave dot umbr dot cas dot cz
I found this error only on FC2, on my Gentoo I have PHP 4.4.0 which works fine. (I have changed OS field)
 [2005-11-28 13:20 UTC] gentoo at slave dot umbr dot cas dot cz
you mean it's fixed in CVS and will be released in PHP 4.4.2, don't you?
 [2005-11-28 13:22 UTC] tony2001@php.net
Exactly.
And this issue has been already reported several times.
 [2005-11-28 13:22 UTC] gentoo at slave dot umbr dot cas dot cz
sorry , i have changed status to open because i had page "edit submission" with "open" status while you added the answer
 [2005-11-28 13:23 UTC] gentoo at slave dot umbr dot cas dot cz
hmmm, sorry for reporting. I have tried to search but not found this error. Could you send me some link or tell the keywords to find it?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 10:01:30 2024 UTC