php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46093 array pointer is different from other versions
Submitted: 2008-09-16 11:46 UTC Modified: 2008-10-08 18:13 UTC
From: home at oxwiz dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.6 OS: CentOS release 4.6 (Final)
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: home at oxwiz dot com
New email:
PHP Version: OS:

 

 [2008-09-16 11:46 UTC] home at oxwiz dot com
Description:
------------
I know that the array pointer doing...
if passing arrays to functions, the pointer of the argument(within the function) is set to First.
and after the foreach, the pointer is set to First; 

But, some version of PHP (like 5.2.6 and 5.2.7-dev) array pointer is different from other version.
Also, I ever seen it within one of early version of 5.2.6.

test result... 
expected result: 5.0.4(FC 4) , 5.1.6(centos 5)  
actual result:   5.2.6(centos 4.6) , 5.2.7-dev(centos 4.6)

Reproduce code:
---------------
<?
echo "PHP VER. ".phpversion()."<br><br>";
$a = array('aa'=>'aa','bb'=>'bb','cc'=>'cc');
$aa = array('a'=>$a,'b'=>$a,'c'=>$a);
function testLoop($datas) {
    while (is_array($datas) && list($dk,$data) = each($datas)){
        echo $dk ."<br>";
    }
}

//next ($aa);
foreach ($aa as $ak=>$av) unset ($aa[$ak]['bb']);
list($k,$v) = each($aa);
echo "$k , $v <br>";
echo "testLoop : unexpected result<br>";
testLoop($aa);
echo "<br>rest & testLoop : expected result<br>";
reset($aa);
testLoop($aa);
?>

Expected result:
----------------
PHP VER. 5.0.4

a , Array 
testLoop : unexpected result
a
b
c

rest & testLoop : expected result
a
b
c


Actual result:
--------------
PHP VER. 5.2.6

b , Array 
testLoop : unexpected result
c

rest & testLoop : expected result
a
b
c


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-08 18:13 UTC] jani@php.net
Pre 5.2.6 result is the unexpected one.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 17:01:29 2024 UTC