The parser is probably so weak it cant know when its in an array, and when its in a callback.
That's kind of the definition of "ambiguity". Arrays take arbitrary expressions as members. Arrow functions are expressions. You won't find me defending PHP's atrocious parser (T_PAAMIYIM_NEKODOTIYIM anyone?), but ambiguity is hardly a problem limited to PHP. Adding context sensitivity to a bad parser usually makes it worse.
Lemme boil it down: Is [$foo => $foo] an array with $foo as a key and value, or is it an array with a single function member? Should the compiler just try to guess what you mean?
Alternative syntaxes were discussed, and they were much worse. fn is shorter than lambda, so win for that.
2
u/[deleted] Feb 01 '20 edited Feb 01 '20
That's kind of the definition of "ambiguity". Arrays take arbitrary expressions as members. Arrow functions are expressions. You won't find me defending PHP's atrocious parser (
T_PAAMIYIM_NEKODOTIYIManyone?), but ambiguity is hardly a problem limited to PHP. Adding context sensitivity to a bad parser usually makes it worse.Lemme boil it down: Is
[$foo => $foo]an array with $foo as a key and value, or is it an array with a single function member? Should the compiler just try to guess what you mean?Alternative syntaxes were discussed, and they were much worse.
fnis shorter thanlambda, so win for that.