Re: [RFC]Discuss] Syntax for Arrow Functions
| From: | ilija dot tovilo at me dot com | Date: | Wed, 31 May 2017 21:35:31 +0000 |
| Subject: | Re: [RFC]Discuss] Syntax for Arrow Functions | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-99306@lists.php.net to get a copy of this message | ||
I think it’s worth noting that the people most excited about arrow functions are probably the ones
with a more functional approach.
Those kinds of side effects are usually avoided.
I also have nothing against capturing by reference. Given the last example:
fn($item) => $array[] = $item
All you have to do is glance a few characters to the left to see that $array is not a parameter and
thus must be captured. And again, since it’s pretty obvious to see if you’re mutating the
variable (spot the equal sign) this shouldn’t cause too many surprises. Only scenario I can think
of is passing it to another function as a reference. But then again, no one ever complains about
that in other languages.
Ilija
On 31 May 2017, 23:11 +0200, Levi Morrison <levim@php.net>, wrote:
> > I can’t think of a scenario where capturing by reference would be helpful in
> > a single line closure.
>
> function($item) use($array) {
> return $array[] = $item;
> }
>
> It's actually one of the first closures I discovered in the wild when
> looking for closures that would be candidates for the short form.