On Fri, 30 Oct 2020 at 19:07, Rowan Tommins <[email protected]> wrote:
> Just to be clear, the major gain here is not replacing the 10 characters
> "function()" with the 7 characters "fn() =>", it is eliminating the list
> of captured variables. So you would get equally clean code with a
> "capture all" syntax, such as:
>
> return $connection->transactional(function() use(*) {
>
> or Sara's suggestion from earlier today:
>
> return $connection->transactional(function() use($) {
>
Any of those would be a large improvement over the current situation I
agree.
That being said, for what it's worth, I've also proposed on the PR on GitHub
<https://github.com/php/php-src/pull/6246#issuecomment-719074545> an
alternative syntax for a closure that takes no parameters and inherits the
full scope:
$connection->transactional({
// ...
});
So yes, this would be a closure:
$a = {};
I'm not sure if this would be considered (additionally, not as a
replacement), but I thought it'd be worth mentioning, as it would offer an
elegant solution for methods whose body is pretty much only a call to a
method wrapping a closure.
— Benjamin