Re: [RFC] Bare Name Array

From: Date: Tue, 03 Jun 2014 01:14:05 +0000
Subject: Re: [RFC] Bare Name Array
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-74701@lists.php.net to get a copy of this message
On 1 Jun 2014, at 18:59, Andrea Faulds <ajf@ajf.me> wrote: > 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. Something I’m considering adding to the RFC is support for quoted names, such that you could do this: [“stringKey”: 3] Now, obviously, you can already do the same with the double arrow: [“stringKey” => 3] If that’s the case, then what’s the advantage? Well, it is even closer to JSON and JavaScript now than before. By adding this, we’d have the bareName: and “quoted name”: syntaxes established in arrays, and PHP developers would become familiar with them. (Incidentally, Apple’s new Swift language announced a few hours ago uses [“key”: 3] for their hash map literals, though that’s a bit off-topic.) With that groundwork laid, a new RFC could be created proposing object literals with identical syntax to JSON’s objects, meaning you could paste JSON into PHP and (unless it had dollar signs) it would be perfectly valid PHP code and parse as you expect. It would support the “quoted key”: and unquotedKey: formats, but none other, thus aligning itself with JavaScript (and hence JSON, which uses “quoted key”: exclusively). That would also be useful for creating disposable objects. At present, the closest thing we have is immediately casting arrays to objects, which is tedious, as well as acting weirdly in some situations (integer keys in particular). The JSON stuff is not, however, part of this RFC. It’s a separate RFC and thing I would implement if a quoted name syntax was added to this RFC and it passed. Also, I haven’t yet added “quoted key”: syntax, but I’m considering it. -- Andrea Faulds http://ajf.me/

« previous php.internals (#74701) next »