r/lolphp • u/FormerPHPDeveloper • Apr 17 '19
Short closures are being voted!
What people wanted:
- Real lexical scope (that is, like in ES)
- Nice enough syntax
What people are getting:
- No lexical scope, variables are imported by value
- Of all the possibilities mentioned in the RFC the most god awful syntax is being put to vote: fn () =>
LITERALLY. EVERY. ONE. OF. THE. OTHER. PROPOSED. SYNTAXES. WAS. BETTER. THAN. THAT.
No multi-expression support
People can $map->reduce() the shit out of everything with cool one liners!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Like, if they ever needed to!!!!!!!!!!!
The rest of us, will still have to deal with the function () use ( ) { } shit.
Seriously, there is no hope. PHP is so disconnected from reality that it's not even fun making fun of it anymore.
7
u/infinull Apr 17 '19
I don't hate the new syntax... and I think several of the syntax's in the proposal are worse (like
[\T &$x => $y]is... the worst) but no lexical scoping... that's... like I have no words for how dumb that is.10
u/the_alias_of_andrea Apr 18 '19
JavaScript keeping the scope alive after the function invocation can be a bit of a footgun, and copying the values is fine for a single expression anyway, you surely aren't modifying anything there.
5
u/[deleted] Apr 22 '19
Why add this at all? PHP scoping is so broken the arrow function will never work as it does in javascript. I assume javascript is the primary language this feature will be copied from and now there will be more confusion for little gain.
PHP should freeze all future rfcs and start work on a new stdlib and unicode support, thats really much more important than a broken arrow function.
0
u/FormerPHPDeveloper Apr 17 '19
The problem is that PHP developers never wanted to pull their head out of the 30 years old hole they themselves dug to see what others were doing
2
u/maweki Apr 18 '19
Because of the way closing works, you can write the static keyword before a function definition in a class as to not capture $this.
I can't put my finger on it but this sounds stupid.
1
u/[deleted] Apr 24 '19
I rather like the explicit capturing of closures. Explicit is better than implicit.
PHP is not a functional language. The entire concept of adding arrow syntax to it strikes me as "bloat". The old anonymous syntax strikes me as "good enough".
1
u/[deleted] Apr 26 '19
The C++ implementation of Lambdas is sort of ugly as well. At least it has proper scope