Hi Nuno, thank you very much for kicking this off! The current state of
short closure is very limited and I believe it was a stepping stone to get
to this one.
This time there's no drawback of making fn a reserved keyword since it
already is.
This change will lead to better consistency and it will fill in the
expectation gap when using short closure in PHP.
Best of luck for us on this RFC.

On Sat, Oct 3, 2020, 23:09 Nuno Maduro <enunomad...@gmail.com> wrote:

> Hey internals,
>
>
> A few days ago I opened a pull request that adds support for multi-line
> arrow functions in PHP: https://github.com/php/php-src/pull/6246.
>
>
> As you may already know, PHP 7.4 has introduced one-liner arrow functions
> (aka short closures). Now, this pull request adds the possibility of those
> arrow functions to be multi-line. Just like in Javascript, or Hack. Let's
> see an example:
>
>
> ```php
>
> $users = [/** */];
>
> $guestsIds = [/** */];
>
> $repository = /** */;
>
>
> $guests = array_filter($users, fn ($user) => {
>
>   $guest = $repository->findByUserId($user->id);
>
>
>   return $guest !== null && in_array($guest->id, $guestsIds);
>
> });
>
> ```
>
>
> In short, the advantages are:
>
> ```
>
> $values = array_filter($values, function ($value) use ($first, $second,
> $third) {
>
> // vs
>
> $values = array_filter($values, fn ($value) => {
>
> ```
>
>
> - Multi-line arrow functions don't require the `use` keyword to be able to
> access data from the outer scope.
>
> - Also, in some cases, `fn (/** */) => {` is just shorter and simpler than
> `function (/** */) use (/** */) {`.
>
>
> This pull request has been very well received by the community on Github,
> and also on Twitter:
> https://twitter.com/enunomaduro/status/1311572174256340992.
>
>
> So, I am writing this email to get your feedback about having this feature
> in the core of PHP. Note that, if eventually, you think it is a good idea
> to create an RFC on this, I will need to get some RFC karma - my wiki
> account is nunomaduro.
>
>
> Regards,
>
> Nuno - https://twitter.com/enunomaduro.
>

Reply via email to