Re: RFC - Array slice syntactic sugar
| From: | Vik Hudec | Date: | Fri, 20 Mar 2015 13:47:18 +0000 |
| Subject: | Re: RFC - Array slice syntactic sugar | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-85292@lists.php.net to get a copy of this message | ||
Hi Rowan,
On Fri, 2015-03-20, at 13:17, Rowan Collins wrote:
> I personally like the idea of string offsets having similar but slightly
> different syntax from array offsets, to make clear which you're using. I
> use {} instead of [] for that reason, but at the moment the syntaxes are
> completely interchangeable as far as I can tell.
I'm in exactly the same situation; I'd thought for ages that the curly-brace
syntax was only valid for string offsets, so I use them in favour of square
brackets to avoid confusion.
I'd support reserving curly-braces for string offsets only (and vice-versa
for square brackets / arrays).
One awkward edge-case is where a class implements both __toString() and
ArrayAccess. It would be nice if you could distinguish which type of offset
you're accessing without casting.
Theoretical phpt test: http://pastebin.com/9b6YLC29
Vik