Re: RFC - Array slice syntactic sugar

From: Date: Fri, 20 Mar 2015 21:13:50 +0000
Subject: Re: RFC - Array slice syntactic sugar
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-85333@lists.php.net to get a copy of this message
On 20 March 2015 at 20:52, Stanislav Malyshev <smalyshev@gmail.com> wrote: > I'm not sure how such operation would be useful, and it definitely would > not be intuitive, as $array[0] and $array[0:1] (assuming non-inclusive > semantic, or [0:0] with inclusive semantics) would return completely > different things. That would happen even if the array has only numeric > keys! This is the main problem with this syntax - unlike most languages > where it is used, PHP arrays are not vectors, they are ordered hashmaps. > Sometimes this is very convenient, sometimes - like for this syntax - it > is not. I think this is the major reason why such proposals failed in > the past. > It would give different results, for a reason. There is currently no way to get an array item by positional index, whilst preserving the keys. This RFC will allow that, with the inclusion of the symbol that will be required for this RFC (slicing by key can be a separate RFC; and is not covered by this RFC). So, if i want to get the items from position 1 through 5, I can use [*1:5] and I will get an array of the items in position 1,2,3,4 and 5; regardless of their keys, as an array.

« previous php.internals (#85333) next »