Re: RFC: Support for multi-line arrow functions
| From: | Benjamin Morel | Date: | Fri, 30 Oct 2020 21:44:41 +0000 |
| Subject: | Re: RFC: Support for multi-line arrow functions | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112152@lists.php.net to get a copy of this message | ||
On Fri, 30 Oct 2020 at 19:07, Rowan Tommins <rowan.collins@gmail.com> 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