Re: Re: [RFC][Discuss] Arrow Functions
| From: | David Walker | Date: | Tue, 31 Jan 2017 04:41:01 +0000 |
| Subject: | Re: Re: [RFC][Discuss] Arrow Functions | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98060@lists.php.net to get a copy of this message | ||
On Mon, Jan 30, 2017 at 18:12 Andrea Faulds <ajf@ajf.me> wrote:
> Hi Levi,
>
> Levi Morrison wrote:
> > Here is an example of an existing closure:
> >
> > function ($x) use ($arr) {
> > return $arr[$x];
> > }
> >
> > This RFC proposes syntax and semantics to simplify this common usage to:
> >
> > fn($x) => $arr[$x]
> >
>
> Is it necessary to introduce a new keyword, fn?
>
> I think you'd get a similar benefit from:
>
> function($x) => $arr[$x]
>
> Likewise, is it necessary to restrict auto-capture to the => syntax?
> Couldn't we allow the following?
>
> function ($x) {
> return $arr[$x];
> }
>
This looks too similar to the current syntax, just ignoring the use()
statement. I would add a concurance that => syntax is slightly awkward when
used within an array element
$a = [
'func' => fn($x) => Class::method($x),
];
But I'm not overly certain of a different syntax to handle this.
I would support expanding to function over fn, to make it more
readable/keep the same reserved word. (Although not too certain to the
complexity in the parser)
Otherwise +1, I like this.
--
Dave