Bug #75653 [Dup->Csd]: array_values don't work on empty array
| From: | nikic@php.net | Date: | Fri, 12 Jan 2018 17:34:43 +0000 |
| Subject: | Bug #75653 [Dup->Csd]: array_values don't work on empty array | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213503@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75653&edit=1
ID: 75653
Updated by: nikic@php.net
Reported by: math dot piot at gmail dot com
Summary: array_values don't work on empty array
-Status: Duplicate
+Status: Closed
Type: Bug
Package: Arrays related
Operating System: Debian 9
PHP Version: 7.2.0
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8c73fc8027a7293e81c0b2e8dc2674fe34f1eb59
Log: Fixed bug #75653
Previous Comments:
------------------------------------------------------------------------
[2017-12-08 13:55:49] spam2 at rhsoft dot net
looks like a terrible BC break in 7.2 and i can remember recently that we wrote code to get the
first remaining value after cleanup by $first = array_values($array)[0] which would no longer work
with PHP 7.2
preserve keys here makes no sense
7.1.12:
array(2) {
[0]=>
string(5) "data2"
[1]=>
string(5) "data3"
}
7.2.1-dev:
array(2) {
[1]=>
string(5) "data2"
[2]=>
string(5) "data3"
}
------------------------------------------------------------------------
[2017-12-08 13:55:48] requinix@php.net
Basically the same as bug #75433
------------------------------------------------------------------------
[2017-12-08 13:44:53] math dot piot at gmail dot com
Description:
------------
If I do a array_value on an empty array, it doesn't work. It works well if there is as least 1
value in the array.
Test script:
---------------
$array[] = 'data1'; // I want [0 => 'data1']
unset($array[0]); // I want []
$array = array_values($array); // I want [] but keys resetted
$array[] = 'data2'; // I want [0 => 'data2']
$array[] = 'data3'; // I want [0 => 'data2', 1 => 'data3']
var_dump($array);
Expected result:
----------------
array(2) {
[0]=>
string(5) "data2"
[1]=>
string(5) "data3"
}
Actual result:
--------------
array(2) {
[1]=>
string(5) "data2"
[2]=>
string(5) "data3"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75653&edit=1