php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #21998 array_pop() moves current element pointer since 4.3.0
Submitted: 2003-02-01 13:42 UTC Modified: 2003-02-05 03:10 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: php at alterego dot dp dot ua Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.0 OS: all
Private report: No CVE-ID:
 [2003-02-01 13:42 UTC] php at alterego dot dp dot ua
<?
  $a = array("a", "b", "c");
  each($a);
  array_pop($a);
  var_dump(each($a));
?>

This prints "bool(false)" in 4.3.0 (current element pointer points somewhere out of the array) and var_dump($a[0]) in 4.2.3 (array is reset after array_pop).

I had to add many additional reset()'s after installing 4.3.0.

How array_pop() (and may be others) affects current element pointer is not documented, so this behavior is not a bug. The only purpose of writing all this is that I want to know how array_pop() will work in future PHP releases.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-01 15:08 UTC] magnus@php.net
Array related. 
One of these commits broke it. 
 
revision 1.180 
date: 2002/08/01 17:34:31;  author: rodif_bl;  state: Exp;  
lines: +12 -15 
array_pop wasnt setting next index 
---------------------------- 
revision 1.179 
date: 2002/08/01 16:44:47;  author: sniper;  state: Exp;  
lines: +1 -4 
That was not correct.. 
---------------------------- 
revision 1.178 
date: 2002/08/01 16:39:52;  author: sniper;  state: Exp;  
lines: +5 -2 
Reset index when doing array_pop() 
 
 [2003-02-03 00:39 UTC] sniper@php.net
magnus@php.net: I reverted my changes, not my fault. :-p

But there is indeed some bug in this, since array_pop()
should not affect the current key. 


 [2003-02-03 10:51 UTC] sniper@php.net
Clarification: In PHP 4.2.3, the current array position
was reset after array_pop() and array_shift().

 [2003-02-03 11:02 UTC] sniper@php.net
I have fixed this now in CVS. But the docs should mention
that the pointer is reset by array_pop/array_shift.


 [2003-02-05 03:10 UTC] php at alterego dot dp dot ua
Thanks for the best web scripting language...
 [2004-01-30 02:12 UTC] nilsen at softease dot no
I just upgraded a machine here from 4.1.2 (redhat default installation) to 4.3.4.

while (count($tree) > 1){
        $tree[count($tree) - 2]["SELECTED"]["Children"] = $tree[count($tree) - 1];
        array_pop($tree);
}

The above doesn't work after upgrading. We had to change it to this:

while (count($tree) > 1){
        $tree[count($tree) - 2]["SELECTED"]["Children"] = $tree[count($tree) - 1];
        $tree = array_slice($tree,0,count($tree) - 1);
}

Wasn't this bug sorted out?


Thanks.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 07:02:14 2014 UTC