Re: [RFC] Bare Name Array
| From: | Andrea Faulds | Date: | Tue, 03 Jun 2014 20:44:36 +0000 |
| Subject: | Re: [RFC] Bare Name Array | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-74731@lists.php.net to get a copy of this message | ||
On 3 Jun 2014, at 21:34, Rowan Collins <rowan.collins@gmail.com> wrote:
> Personally, I think its distinctive role as turning a bare-word into a string key is the only
> justification for this syntax at all, and if I ever used it, it would be exclusively for
> "struct"-type arrays, where the keys adhered to a strict template. In fact (similar to the
> discussion of "symbols" earlier) a new "struct" type (copy-on-write like an
> array, but with keys never added or removed after declaration) might be an interesting idea to
> explore.
>
> Allowing quoted strings on the left-hand side also opens up questions about other
> possibilities: if you can have quoted strings, why not numeric keys as well? And then, what about
> [$foo: 'bar']? Is that still a syntax error, and if so, will it be obvious to users why
> that is? And then we're back to the bare-word=constant problem again: the only distinction
> between ":" and "=>" would be "force the left-hand side to be evaluated
> as a string, not a constant name", which just seems kind of confusing.
Yeah. Upon further reflection, I think supporting strings too would be silly here. My only real
rationale was to parallel my hypothetical future object literals, but that’s silly. (Also, looks
like I can’t implement them anyway.)
On a different topic, structs are indeed an interesting idea. Perhaps they could be a resurgence of
PHP4-style objects? I note that Apple’s new “Swift” language has structs and classes, where it
seems structs are essentially identical to classes except that they have value instead of reference
semantics. But that is a discussion for another thread.
--
Andrea Faulds
http://ajf.me/