From: epoc_32 at yahoo dot co dot ukXXX
Operating system: Windows XP
PHP version: 5.1.2
PHP Bug Type: Scripting Engine problem
Bug description: Array doesn't pop when array is created inside array_pop
Description:
------------
If you create an array inside array_pop(), expecting that array to be
popped then it isn't even though the last element of that array is
returned as expected.
Creating the array on the previous line makes array_pop() behave as
expected.
This behaviour doesn't occur in PHP4.3.x on FreeBSD. I only noticed it
when I upgraded to PHP 5.1.2 on my home WinXP machine though it's possible
it was broken but I didn't notice it in 5.0.x
Reproduce code:
---------------
$a=array(0, 1, 2, 3, 4, 5); // Set array first.
$offcut=array_pop($a); // Then pop array.
$length=count($a);
echo "<pre>Array offcut: "
.$offcut."\nArray length: "
.$length."\nLast element: "
.$a[$length-1]."</pre>\n";
$offcut=array_pop($a=array(0, 1, 2, 3, 4, 5)); // Set and pop at the same
time.
$length=count($a);
echo "<pre>Array offcut: "
.$offcut."\nArray length: "
.$length."\nLast element: "
.$a[$length-1]."</pre>\n";
Expected result:
----------------
Array offcut: 5
Array length: 5
Last element: 4
Array offcut: 5
Array length: 5
Last element: 4
Actual result:
--------------
Array offcut: 5
Array length: 5
Last element: 4
Array offcut: 5
Array length: 6
Last element: 5
--
Edit bug report at http://bugs.php.net/?id=36451&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=36451&r=trysnapshot44
Try a CVS snapshot (PHP 5.1):
http://bugs.php.net/fix.php?id=36451&r=trysnapshot51
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=36451&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36451&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=36451&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=36451&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=36451&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=36451&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=36451&r=support
Expected behavior: http://bugs.php.net/fix.php?id=36451&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=36451&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=36451&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36451&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36451&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36451&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=36451&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=36451&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=36451&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=36451&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=36451&r=mysqlcfg