Bug #75611 [Opn->Nab]: array_slice BC breaking

From: Date: Fri, 01 Dec 2017 15:30:05 +0000
Subject: Bug #75611 [Opn->Nab]: array_slice BC breaking
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212868@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75611&edit=1 ID: 75611 Updated by: peehaa@php.net Reported by: nodex at icloud dot com Summary: array_slice BC breaking -Status: Open +Status: Not a bug Type: Bug Package: Arrays related Operating System: MacOs and Ubuntu PHP Version: 7.1.12 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Previous Comments: ------------------------------------------------------------------------ [2017-12-01 15:29:07] peehaa@php.net Also is in the docs: > If the offset is larger than the size of the array then returns an empty array. Also it seems like you are confusing the length (3rd param) with the offset (2nd param) ------------------------------------------------------------------------ [2017-12-01 15:25:57] peehaa@php.net Always been like that: https://3v4l.org/tPsel ------------------------------------------------------------------------ [2017-12-01 15:22:08] nodex at icloud dot com Description: ------------ When using array_slice on a smaller array, PHP 7.1.4 (untested newer versions) returns a blank array if the size of the array is less than the $length parameter of array_slice In php 5.6 this was not the case, the function simply returned the entire array if it was shorter. Surely this must be a bug or are we now meant to count the array to check it's the right size before calling array_slice? Test script: --------------- # Basic reproduction test $array = range(0,10); $slice = array_slice($array,12); // same with and without the offset parameter! print_r($slice); // Empty! $array = range(0.5); $slice = array_slice($array,3); print_r($slice); // As expected 3 elements! ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75611&edit=1

« previous php.bugs (#212868) next »