php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #5226 arrayfields reorganized when using array_pop
Submitted: 2000-06-25 18:56 UTC Modified: 2002-10-27 19:07 UTC
From: bretschneider at freestyling dot de Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.0.0 Release OS: freebsd 3.1
Private report: No CVE-ID: None
 [2000-06-25 18:56 UTC] bretschneider at freestyling dot de
<?
  $A[1] = 'A';
  $A[2] = 'B';
  $A[3] = 'C';
  
  $DUMP = array_pop($A);
  
  for ($i=0; $i<=sizeof($A); $i++) {
    print "$i = ".$A[$i]."<br>\n";
  }
?>

returns:

0 = A
1 = B
2 = 

but should return 

0 =
1 = A
2 = B

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-06-25 19:01 UTC] stas at cvs dot php dot net
AFAIU that's exactly what pop should do - pop element from array.
Why should it insert empty element on top?
 [2000-06-28 10:20 UTC] stas at cvs dot php dot net
Presently, all splice-derived functions reorder numeric keys.
There's not much to do about it, since it's the way Zend Engine handles numeric hash keys.
Changing it either way won't bring more consistent  functionality, so in the meantime it is just as it is.
 [2001-04-04 00:49 UTC] cnewbill@php.net
Reclassifying as a feature request, regardless of whether it happens anytime soon. :)

-Chris

spinn@spinnwebe.com adds...

This is a repeat of 5226, but I couldn't add anything without a password, which I didn't have.

In that bug, stas@cvs.php.net didn't understand the example that was given. What happens is this: if you have

$a[5]="five"; 
$a[6]="six";

and then do array_pop($a), you now have $a[0]="five", not $a[5]="five", as I would expect.

Despite not understanding the example, stas answered the question: that's the way the zend engine works. But you don't see that as a problem?

 [2001-04-04 00:51 UTC] cnewbill@php.net
oops, forgot feature request.

-Chris
 [2002-10-27 19:07 UTC] sterling@php.net
Except that its not a feature request, its a bogus bug report... ;-)

It imho shouldn't be changed in the first place, but it would also break bc so fully that it will never change.
 [2003-02-10 21:41 UTC] gstrash at cyberstreet dot com
Thats kinda bs.
 for ($i=0; $i<=sizeof($A); $i++) {
    print "$i = ".$A[$i]."<br>\n";
  }
?>

returns:

0 = A
1 = B
2 = 

but should return 

0 =
1 = A
2 = B


i think you misunderstand what he is saying.  the for loop he created to dump the array is adding the "2 = "

what woudl be displyed in a var_dump or print_r would be
Array( [0]=>A,[1]=>B)
when it should be 
Array( [1]=>A,[2]=>B)
since the original displays
Array ( [1] => A [2] => B [3] => C )
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 04:03:37 2021 UTC