Den 2017-06-05 kl. 19:55, skrev Rowan Collins:
On 5 June 2017 18:17:06 BST, Fleshgrinder <p...@fleshgrinder.com> wrote:
Could someone explain me again what the problem with the simple
fat-arrow and normal parenthesis is? Cannot find it anymore (too many
messages in too many thread I guess). I would guess that it has to do
with the arbitrary look-ahead that is required to check for the fat
arrow before the lexer knows that this is a short closure and not some
parenthesis that simply groups something.
I think it's not just a case of implementation problems, it's actually
ambiguous with current syntax:
$foo = array( ($x) => 42 );
Sure, those inner brackets are redundant, so it's not likely to break much
actual code, but it's kind of weird to have this one case magically turn into a
closure, when anything else you put in those brackets would just be used as the
array key:
$foo = array( f($x) => 42 );
$foo = array( ($x+1) => 42 );
$foo = array( (42) => $x );
$foo = array( (X) => 42 );
$foo = array( ($x) => 42 );
$foo = array( ("$x") => 42 );
Even if we could teach the parser to understand it, I'd personally be against it for
the difficulty of *humans* parsing it. I find shorthand closures hard enough to read
anyway, especially when people suggest things like ($x) => ($y) => $x * $y * $z;
Regards,
+1, think you nailed it here :) One of the reasons I prefer the ==> syntax.
r//Björn
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php