Re: Arrow function expressions in PHP
| From: | Levi Morrison | Date: | Sat, 26 Sep 2015 18:37:33 +0000 |
| Subject: | Re: Arrow function expressions in PHP | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-88518@lists.php.net to get a copy of this message | ||
On Sat, Sep 26, 2015 at 12:31 PM, Levi Morrison <levim@php.net> wrote:
> On Sat, Sep 26, 2015 at 11:07 AM, Rowan Collins <rowan.collins@gmail.com> wrote:
>> On 26/09/2015 17:17, Levi Morrison wrote:
>>>
>>> What concerns do you have about
fn($x) => $x * 2 or
>>> `function($x) =>
>>> $x * 2`? I will be writing a proper RFC later but I wanted to get
>>> discussion going now.
>>
>>
>> If a keyword is required next to the parameters, having the => as a separate
>> token looks a bit weird. It no longer matches other languages, so how about
>> thinking a bit further outside the box?
>
> Thank you for the feedback. I feel like the rest of what you proposed
> was a bit too far outside of the box. For what it is worth no token
> after the paren is necessary – you could do fn($x) $x * 2 (or
> function($x) $x * 2). I think this is a case where more syntax
> helps.
Here they are on separate lines so you can see things more clearly:
$output = array_map(function($x) $x * 2, $input);
$output = array_map(function($x) => $x * 2, $input);
I think the arrow helps.