Re: [RFC] Bare Name Array
| From: | Rowan Collins | Date: | Sun, 01 Jun 2014 20:20:29 +0000 |
| Subject: | Re: [RFC] Bare Name Array | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-74686@lists.php.net to get a copy of this message | ||
On 01/06/2014 21:09, Rowan Collins wrote:
On 01/06/2014 20:56, Andrea Faulds wrote:Apparently, I was half-right:While Perl’s => is for unquoted strings, PHP’s is for quoted strings, which is bizarre considering PHP is Perl-inspired. :)That's not really "the opposite". IIRC, the => is considered to be "syntactic sugar" for the ",". The quotes are optional in both cases.
It is often more readable to use the |=>| operator between key/value pairs. The |=>| operator is mostly just a more visually distinctive synonym for a comma, but it also arranges for its left-hand operand to be interpreted as a string if it's a bareword that would be a legal simple identifier. |=>| doesn't quote compound identifiers, that contain double colons.[ http://perldoc.perl.org/perldata.html ] Testing confirms that using a bareword before a comma is legal, but will produce a warning that it "may clash with future reserved word" (so rather similar to JS); with => that conflict is avoided for simple keys, similar to your proposal here. -- Rowan Collins [IMSoP]