On Wed, Mar 24, 2021 at 1:34 PM Christian Schneider <cschneid@cschneid.com>
wrote:
> Am 24.03.2021 um 18:15 schrieb Chase Peeler <chasepeeler@gmail.com>:
> > I guess my one question would be why we didn't support auto-capture when
> we
> > first implemented anonymous functions, and if there was a reason, why
> does
> > that no longer apply?
>
> My guess would be that it was seen as one of PHP's big strength that
> variables don't just leak into other contexts but that it has to be done
> explicitly.
>
> Now with arrow functions both the benefit of auto-capturing is bigger
> compared to the actual function 'body', it normally only spans a line or
> two and (for me personally) the absence of {} also kind of make the leakage
> fit my mental model more easily.
>
> For these reasons I think I lean towards -1 for both
> https://wiki.php.net/rfc/short-functions
> <
> https://wiki.php.net/rfc/short-functions> and
> https://wiki.php.net/rfc/auto-capture-closure
> <
> https://wiki.php.net/rfc/auto-capture-closure>
> as they add more syntax
> without (IMHO) a huge benefit.
>
> You might be able to convince me otherwise though ;-)
>
I don't really have anything against auto-capture, was just kind of
curious. I guess it is somewhat similar to how x = function(){...} and x =
() => {} work in javascript with respect to "this".
I do think it makes sense to only do auto-capture on the short syntax, so
that you still have the ability to fallback to the long syntax if you don't
want auto-capture, since there are definitely use-cases where it wouldn't
be make sense.
,
> - Chris
>
>
--
Chase Peeler
chasepeeler@gmail.com