Bug #75653 [Com]: array_values don't work on empty array
| From: | spam2 at rhsoft dot net | Date: | Fri, 08 Dec 2017 13:55:50 +0000 |
| Subject: | Bug #75653 [Com]: array_values don't work on empty array | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213014@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
Comment by: spam2 at rhsoft dot net
Reported by: math dot piot at gmail dot com
Summary: array_values don't work on empty array
Status: Duplicate
Type: Bug
Package: Arrays related
Operating System: Debian 9
PHP Version: 7.2.0
Block user comment: N
Private report: N
New Comment:
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"
}
Previous Comments:
------------------------------------------------------------------------
[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