[RFC] Bare Name Array
| From: | Andrea Faulds | Date: | Sun, 01 Jun 2014 17:59:13 +0000 |
| Subject: | [RFC] Bare Name Array | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-74665@lists.php.net to get a copy of this message | ||
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.
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.
The two proposals will be voted on separately, but I’m making a single RFC as they’re related
and complement each other.
The RFC is here: https://wiki.php.net/rfc/bare_name_arrays
Please read it and tell me your thoughts. I already have a completely working patch with tests
available.
Thanks!
--
Andrea Faulds
http://ajf.me/