Re: Arrow function expressions in PHP
| From: | Rowan Collins | 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:
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]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 doHere they are on separate lines so you can see things more clearly:fn($x) $x * 2(orfunction($x) $x * 2). I think this is a case where more syntax helps.$output = array_map(function($x) $x * 2, $input);$output = array_map(function($x) => $x * 2, $input);I think the arrow helps.