Re: RFC - Array slice syntactic sugar
| From: | Rowan Collins | Date: | Fri, 20 Mar 2015 18:17:06 +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 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-85314@lists.php.net to get a copy of this message | ||
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 thoughWhy? 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]