Re: [RFC][Discuss] Arrow Functions
| From: | Aaron Piotrowski | Date: | Sat, 04 Feb 2017 00:25:59 +0000 |
| Subject: | Re: [RFC][Discuss] Arrow Functions | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98160@lists.php.net to get a copy of this message | ||
> On Feb 3, 2017, at 2:34 PM, ilija.tovilo@me.com wrote:
>
> I like the suggested syntax. The only drawback I see is that it inhibits the future addition of
> union types for closures:
>
> |int | float $x| => $x
>
> Adding parentheses of course resolves the issue but looks a bit awkward:
>
> |(int | float) $x| => $x
>
> Apart from that I have nothing to complain about. I'd be happy either way.
>
While it may be ugly, I do not believe that this has any ambiguity.
$callback = |int|float $x| => $x ** 2;
When the second | is not followed by =>, the parser should be able to discern that a union type
is being used.
Regards, Aaron Piotrowski