Bug #67693 [NEW]: incorrect push to the empty array
| From: | dvlasov at parallels dot com | Date: | Mon, 28 Jul 2014 05:29:03 +0000 |
| Subject: | Bug #67693 [NEW]: incorrect push to the empty array | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-186833@lists.php.net to get a copy of this message | ||
From: dvlasov at parallels dot com
Operating system: ubuntu 14.04 (32 bit)
PHP version: 5.5.15
Package: Arrays related
Bug Type: Bug
Bug description:incorrect push to the empty array
Description:
------------
When the initial one element array, starting with -1 index, is poped,
and afterwards two values are pushed into the obtained empty array, the
second value index is becoming 2147483647, which is obviously an error.
All other starting indexes (-2, 0, 1, 2,...) do not affect array in this
way.
Also, when starting index is > 0, the index of the first element, pushed
into the empty array is kept from the previous key-value pair. Such
behaviour may be also considered erroneous.
Test script:
---------------
<?php
$b=array(-1=>0);
$c=array_pop($b); assert($c == 0);
assert(array_push($b, 0), 1);
assert(array_push($b, 0), 2);
var_dump($b);
assert(array_push($b, 0), 3);
?>
Expected result:
----------------
array(2) {
[0]=>
int(0)
[1]=>
int(0)
}
Actual result:
--------------
array(2) {
[-1]=>
int(0)
[2147483647]=>
int(0)
}
PHP Warning: array_push(): Cannot add element to the array as the next
element is already occupied in
/home/dmitri/workspace/cell/temp/array_push_pop_bug.php on line 8
--
Edit bug report at https://bugs.php.net/bug.php?id=67693&edit=1
--