Re: [RFC] Bare Name Array
| From: | Johannes Schlüter | Date: | Mon, 02 Jun 2014 08:55:41 +0000 |
| Subject: | Re: [RFC] Bare Name Array | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-74694@lists.php.net to get a copy of this message | ||
On Sun, 2014-06-01 at 18:59 +0100, Andrea Faulds wrote:
> Good evening,
>
> I have created an RFC containing two proposals.
>
> The first is a less cumbersome syntax for arrays. At present, string
> keys in arrays are declared like this:
>
> “stringKey” => 3,
>
> That’s a whole five characters, seven including spaces, for your most
> common case (identifier-like key). In JavaScript, you can avoid
> quoting the key for this common case. I propose something similar for
> PHP. Where the key fits the profile of IS_STRING, this RFC proposes
> that you can do this instead:
>
> stringKey: 3,
>
> Now it’s only two characters, three including spaces, for the most
> common case. It makes declaring arrays more convenient.
I don't believe in "less characters is better". I consider having two
syntaxes which work *notably* different confusing.
const FOO = 23;
$a = [
FOO => 42,
FOO: 3.14152
];
will lead to quite confusing results. We shouldn't go there imo.
> The second proposal is a less cumbersome syntax for dereferencing
> arrays with string keys. At present, you need to do this:
>
> $myArray[“foobar”][“andSoOn”][“moreKeys”][“etc”]
>
> That’s four characters per dereference. Yet for objects, only two are
> needed:
>
> $myObject->foobar->andSoOn->moreProps->etc
>
> Thus, this RFC also proposes the following syntax for dereferencing
> arrays with string keys, where said keys fit the profile of IS_STRING:
>
> $myArray:>foobar:>andSoOn:>moreProps:>etc
>
> The :> syntax can be considered provisional, I’m open to better
> alternatives.
Same as above - the benefit is minimal and might be easily misleading.
johannes