Re: Arrow function expressions in PHP

From: Date: Sat, 26 Sep 2015 19:05:55 +0000
Subject: Re: Arrow function expressions in PHP
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-88519@lists.php.net to get a copy of this message
On 26/09/2015 19:37, Levi Morrison wrote:
Thank you for the feedback. I feel like the rest of what you proposed was a bit too far outside of the box. For what it is worth no token after the paren is necessary – you could do fn($x) $x * 2 (or function($x) $x * 2). I think this is a case where more syntax helps.
Here they are on separate lines so you can see things more clearly:
     $output = array_map(function($x) $x * 2, $input);
     $output = array_map(function($x) => $x * 2, $input);
I think the arrow helps.
I meant more that the lack of parens around the whole expression looks odd - the => is no longer just an operator linking two expressions, it's an arbitrary piece of syntax inserted just because it feels like something should go there (and I agree it does look more readable than nothing at all). How about a variant on existing curly braces: fn($x) { $x * 2 } lambda($x) { $x * 2 } Or the arrow inside the parens: fn($x => $x * 2) function($x => $x * 2) My point is that there are plenty of other variants, if we're no longer mimicking the "(params) => expression" syntax of other languages. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#88519) next »