Re: Shorthand proposal for associative arrays
| From: | Richard Jennings | Date: | Fri, 26 Jan 2018 22:44:10 +0000 |
| Subject: | Re: Shorthand proposal for associative arrays | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-101711@lists.php.net to get a copy of this message | ||
In my opinion this suggestion reduces readability and increases cognative
burden and as such I hope it is not included. Regards
On Fri, 26 Jan 2018 at 21:52, Fleshgrinder <php@fleshgrinder.com> wrote:
> On 1/26/2018 7:16 PM, Christian Schneider wrote:
> > Hi there,
> > I have a proposal for a shorthand notation of associative arrays
> borrowed from another language:
> > :$foo
> > would be equivalent to
> > 'foo' => $foo
> > and would work with array, list or []
> >
> > Motivation behind it, maybe someone else finds more good uses:
> >
> > 1) Emulating named parameters with associative arrays like
> > html::img([ 'src' => $src, 'alt' => $alt ]);
> > could be written as
> > html::img([ :$src, :$alt ]);
> > which encourages consistent naming of variables and parameters
> >
> > 2) Simplifying list destructuring with non-integer keys, example taking
> from
>
> http://php.net/manual/en/migration71.new-features.php#migration71.new-features.support-for-keys-in-list
> > foreach ($data as ["id" => $id, "name" => $name]) {
> > becomes
> > foreach ($data as [ :$id, :$name ]) {
> > which reduces redundancy.
> >
> > I implemented a minimal patch (2 lines are added to the parser) to
> implement this which you can find at
> >
> > https://cschneid.com/php/php7_2/assoc_array_shorthand.patch
> >
> > What do you think, is this worth an RFC? I hope I didn't miss an
> existing one :-)
> >
> > Regards,
> > - Chris
> >
> >
>
> Hi Chris!
>
> I really like this proposal.
compact is cumbersome to use, or
> lets
> say, almost impossible without an intelligent IDE. However, what is more
> important is the fact that is would allow for a very readable and usable
> approach for destructuring of associative arrays (as illustrated by your
> example) which is very, very neat. The change is also extremely minimal
> which speaks for it.
>
> I would support you in writing up an RFC for this (if desired).
>
> --
> Richard "Fleshgrinder" Fussenegger
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
Richard Jennings
Jennings Technology Limited
Company Number: 09827512
VAT Number: 224 8864 84