Re: [RFC] Bare Name Array

From: Date: Mon, 02 Jun 2014 06:38:55 +0000
Subject: Re: [RFC] Bare Name Array
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-74691@lists.php.net to get a copy of this message
On Sun, 01 Jun 2014 23:56:03 +0400, Adam Harvey <aharvey@php.net> wrote:
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', 'myKey' => '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.
Hi, Actually Ruby's symbol is like PHP's string. It's immutable and it's interned. Unlike Ruby's strings which are mutable. So the question is in the syntax only...

« previous php.internals (#74691) next »