Re: [RFC] Bare Name Array

From: Date: Sun, 01 Jun 2014 19:56:03 +0000
Subject: Re: [RFC] Bare Name Array
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-74681@lists.php.net to get a copy of this message
On 1 June 2014 12:47, Rowan Collins <rowan.collins@gmail.com> wrote: > On 01/06/2014 18:59, Andrea Faulds wrote: >> >> The first is a less cumbersome syntax for arrays. At present, string keys >> in arrays are declared like this: >> >> “stringKey” => 3, >> >> [...] Where the key fits the profile of IS_STRING, this RFC proposes that >> you can do this instead: >> >> stringKey: 3, > > > Interestingly, I notice Ruby's hash syntax has two variants very similar to > this [http://www.ruby-doc.org/core-2.1.2/Hash.html]. > > However, in that case, the unquoted version represents a use of Ruby's > special "Symbol" type, which is actually a different fundamental type from a > String. So the following actually defines a 2-element hash, with one Symbol > key and one String key: > > foo = { myKey­: 'bar'­, 'myKe­y' => 'bob'­ } > => {:myKey=>"bar", "myKey"=>"bob"} You've mostly pre-empted the question I wanted to ask. :) Andrea, did you consider implementing something more like Ruby's symbols, rather than a variation on the existing array literal syntax? I feel like that might solve any potential ambiguities in terms of constant resolution (as mentioned in another subthread), wouldn't require a separate [foo: bar] variant on the existing syntax, and may be useful in other contexts too (such as array dereferencing). As for the array dereferencing syntax: it should probably be an RFC and patch on its own. To be honest, my initial reaction is negative — I think the proposed syntax blurs the lines between arrays and objects (I know it's a different digraph, but it's going to look really similar when scanning code), and I'm not yet sold on it being particularly useful. Adam, who's living in the future and typing this from an airborne plane. Very exciting.

« previous php.internals (#74681) next »