Re: [RFC] Bare Name Array
| From: | Rafael Kassner | Date: | Sun, 01 Jun 2014 18:47:21 +0000 |
| Subject: | Re: [RFC] Bare Name Array | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-74669@lists.php.net to get a copy of this message | ||
This causes a huge backward incompatibility:
define('KEY', 'foo');
> $data = array(KEY => 'bar');
Should $data have 'foo' or 'KEY' as element? AFAIK, some frameworks use
this constants in array keys.
On Sun, Jun 1, 2014 at 3:37 PM, Andrea Faulds <ajf@ajf.me> wrote:
>
> On 1 Jun 2014, at 19:13, Stas Malyshev <smalyshev@sugarcrm.com> wrote:
>
> > You can already do stringKey => 3 :)
>
> Yes, but then you’ll get:
> Notice: Use of undefined constant stringKey - assumed 'stringKey'
> in Command line code on line 1
>
> > And saving characters is not really
> > a big priority.
>
> Well, we already replaced array() with []. I think it is reasonable to
> consider saving characters in other places. It’s not a *big* priority, no,
> and we shouldn’t do it excessively, but if common cases are cumbersome, we
> should try to deal with them.
>
> Array literals with string keys and dereferencing arrays with string keys
> are extremely common in PHP. So I think this reduction would benefit most
> users, especially those who deal with JSON and the like (which I do a lot
> in my on code), as this makes declaring arrays to be serialised more
> convenient. Also, foobar: just looks nicer than “foobar” =>, especially
> when you have syntax highlighting.
>
> > Changing language syntax and making millions of people
> > to learn new syntax just to save a couple of chars does not look like a
> > big win to me.
>
> We did it for array(), I think we should do it again. Also, yes, millions
> might have to learn the new syntax, but I think it is simple and intuitive.
> It is not difficult to learn, and hey, perhaps millions can benefit,
> especially since both target very common cases (I expect they’re the most
> common, except for numerical indexes) when dealing with arrays.
> --
> Andrea Faulds
> http://ajf.me/
>
>
>
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>