|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2019-11-04 14:36 UTC] bogdan dot hmarnii at gmail dot com
-Status: Open
+Status: Closed
[2019-11-04 14:36 UTC] bogdan dot hmarnii at gmail dot com
[2019-11-04 14:54 UTC] cmb@php.net
-Status: Closed
+Status: Not a bug
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 04:00:01 2025 UTC |
Description: ------------ array_slice() standard function may not work correctly with the Array with the custom integer indexes starting from 1. It is ignoring last element in this type of array. Additionally verified this problem via 3v4l on all php versions, looks like it is existing everywhere. Test script: --------------- <?php // Failing scenario: Custom int keys in array $stack = [ 1 => 'testA', 2 => 'testB', ]; var_dump(array_key_first($stack)); //first key is 1 var_dump(array_slice($stack, 2)); //Possible bug, last element is ignored. Result:[] var_dump(array_slice($stack, 2, null, true)); //preverse_keys = true. Result: [] //Usual working case $stack = ['testA','testB',]; var_dump(array_key_first($stack)); //first key is 0 var_dump(array_slice($stack, 1)); //Last element is not ingored. Result: stack[1]; //Not usual working case $stack = [0 => 'testA', 1 => 'testB',]; //setting customs indexes in the right order var_dump(array_key_first($stack)); //first key is 0 var_dump(array_slice($stack, 1)); //Last element is not ingored. Result: stack[1]; Expected result: ---------------- If we have an array with the custom integer indexes like $array = [1 => '1', 2 => '2']; then array_slice for the last index should return last element in the array. array_slice($array, 2) should return $array[2]. Actual result: -------------- If we have an array with the custom integer indexes like $array = [1 => '1', 2 => '2']; then array_slice for the last index returns empty array. array_slice($array, 2) returns [] (an empty array).