On 11/06/2022 23:01, Deleu wrote:
The RFC does mention that the existing Anonymous Function Syntax
remains untouched and will not be deprecated. Whether the new syntax
is better for nearly all closures will be a personal choice.
I honestly don't think this is how it will be perceived. If this syntax
is approved, people will see "fn" as the "new, better way" and
"function" as the "old, annoying way".
To put it a different way: imagine we had no closure support at all, and
decided that we needed two flavours, one with explicit capture and one
with implicit capture. Would we choose "function" and "fn" as keywords?
The previous discussions talked about use(*) or use(...) and most
people I know that would love this RFC to pass would also dislike that
alternative. It does not have the greatest asset for short closure:
aesthetics. [...] All I can say is that use(*) is not a replacement
for the RFC.
I think you're trying to have it both ways here: if you really believed
that the two syntaxes were going to live side by side, there would be no
reason for "aesthetics" to be any more important for one than the other.
Some people are of the opinion that automatic capture should always have
been the default, and the current syntax is a mistake. I'm fine with
that opinion, but I want people to be honest about it rather than
pretending they're just adding a new option for a narrow use case.
Any attempt to make it explicit defeats the purpose of the RFC.
That depends what you think the purpose of the RFC is, which is what I
want people to be honest about.
If the purpose is to replace long lists of captured variables, an
explicit "capture all" syntax like "use(*)" achieves that purpose
perfectly fine.
Ultimately, I see fn() as "an opt-in to not create a separate scope
for a function".
I disagree with both parts of this:
1) I don't think users will see "fn" as an "opt-in", they'll see it as
"the new normal", and "function" as a rare "opt-out" or a "legacy version".
2) It does still create a separate scope, it just creates a *nested*
scope, which combines two sets of variables, in a way that PHP currently
never does.
Regards,
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php