On 05.10.20 12:15, Deleu wrote:
To me that seems like a great argument in favour of the proposal. If you'll
want all variables to be imported (which in this case makes completely
sense), then `fn() {}` or `fn() => {}` is much less verbose and inline with
the mentality to reach for short closures. We reach for short closures to
avoid `use()` and convey that the outer process is intertwined with the
inner process. `fn()` allows to strengthen the concept that there's no real
separation between running SQL stuff in a `callable` that wraps a database
transaction.

Not necessarily: the arrow functions were specifically implemented for
very short anonymous functions with a return value. Making them more and
more like the existing "function" syntax would lead to having two
different ways of defining anonymous functions that mainly differentiate
themselves by including the parent scope by default or not.

I like the "function () use (*)" suggestion because it is explicit and
opt-in. A shorter syntax like "fn () {}" is less clear, and it could
lead to many people always using fn just because it is faster to write
(and less to think about), which then could lead to unintended side
effects because variables are being copied from the parent scope each
time. When you see a usage of "fn () {}" while reading code you would
not know if the person used it because it was faster to write, or if the
parent scope variables are really needed.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to