Re: [RFC] Short-function syntax
| From: | Nuno Maduro | Date: | Wed, 04 Nov 2020 22:05:22 +0000 |
| Subject: | Re: [RFC] Short-function syntax | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112186@lists.php.net to get a copy of this message | ||
Hey Larry,
In my vision, this proposal is a good addition to PHP exactly as stated in
this pull request (https://github.com/php/php-src/pull/6221): where only
the "=> expr;" is introduced, and not the "fn".
For visual consistency in the future of PHP functions/methods, I think it's
important to differ "=> expr;" from "fn":
- "=> expr;" means "arrow": syntax that defines functions/methods with
one-line return expressions.
- "fn" means "short": syntax that makes functions inherit scope. It's
already in use by arrow short closures (
https://wiki.php.net/rfc/arrow_functions_v2
).
Therefore, from my understanding, your proposal would allow all the
following things to be possible:
```php
// arrow function
function foo() => /** */;
// arrow closure
$foo = function () => /** */;
// fn/short arrow closure ( already introduced in PHP 7.4 )
$foo = fn() => /** */;
class Foo {
// arrow method
poublic function bar() => /** */;
}
```
If this proposal keeps using the "function", and not the "fn", I don't see
any conflict with my Proposal (multi-line short closures -
https://github.com/php/php-src/pull/6246).
Good luck with the RFC.
- Nuno