[PHP-DOC] #21998 [Ana->Csd]: array_pop() moves current element pointer since 4.3.0 From: philip <email protected>
Date: 02/05/03

 ID: 21998
 Updated by: philip <email protected>
 Reported By: php <email protected>
-Status: Analyzed
+Status: Closed
 Bug Type: Documentation problem
 Operating System: all
 PHP Version: 4.3.0
 New Comment:

This has been fixed in CVS. See:
http://cvs.php.net/cvs.php/phpdoc/en/reference/array/functions/array-shift.xml
http://cvs.php.net/cvs.php/phpdoc/en/reference/array/functions/array-pop.xml
http://cvs.php.net/diff.php/phpdoc/en/language-snippets.ent?r1=1.38&r2=1.39

Thank you for the report :)

Previous Comments:
------------------------------------------------------------------------

[2003-02-03 11:02:08] sniper <email protected>

I have fixed this now in CVS. But the docs should mention
that the pointer is reset by array_pop/array_shift.

------------------------------------------------------------------------

[2003-02-03 10:51:39] sniper <email protected>

Clarification: In PHP 4.2.3, the current array position
was reset after array_pop() and array_shift().

------------------------------------------------------------------------

[2003-02-03 00:39:14] sniper <email protected>

magnus <email protected>: 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-01 15:08:57] magnus <email protected>

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-01 13:42:12] php <email protected>

<?
  $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.

------------------------------------------------------------------------

-- 
Edit this bug report at http://bugs.php.net/?id=21998&edit=1

-- PHP Documentation Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php