Re: RFC - Array slice syntactic sugar
| From: | Alex Bowers | Date: | Fri, 20 Mar 2015 19:04:54 +0000 |
| Subject: | Re: RFC - Array slice syntactic sugar | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-85320@lists.php.net to get a copy of this message | ||
Is everybody happy with the RFC being called 'Slice Operator', or is there
a better name for it?
On 20 March 2015 at 18:17, Rowan Collins <rowan.collins@gmail.com> wrote:
> Leigh wrote on 20/03/2015 16:17:
>
>>
>> For $thing[-1] I think this only works for strings (and I have this
>> implemented, should probably RFC it)
>> https://github.com/lt/php-src/
>> tree/string_negative_offset
>>
>> $thing[-1:] is in scope for arrays though
>>
>>
> Why? Getting the last value of an array is just as useful as getting the
> last character of a string.
>
> It doesn't work *with that syntax*, because -1 is a valid key, just as
> $thing[0] can't mean "first value of array" because it already means "value
> with key 0". That's why I propose a new syntax such as $thing[@0],
> $thing[@-1], etc.
>
> Regards,
> --
> Rowan Collins
> [IMSoP]
>