Re: [RFC] Short-function syntax

From: Date: Wed, 21 Oct 2020 22:17:49 +0000
Subject: Re: [RFC] Short-function syntax
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-112098@lists.php.net to get a copy of this message
On 21/10/2020 21:53, Larry Garfield wrote:
A while back, Nikita mentioned that it should now be easy to offer an abbreviated syntax for functions that are just a single expression. I decided to take a crack at it and it turns out he was right. I thus offer this RFC: https://wiki.php.net/rfc/short-functions
I like it. It fits nicely with my mental model of arrow functions as being special syntax for "functionising" a single expression. It may appeal less to people who see arrow functions as "the better way to write closures", and are hoping to extend them with full procedural bodies.
There's been some discussion on the PR that I'm looping back here for completeness, mainly about using "function" vs "fn" for short named functions.
You could list that under Open Issues on the RFC. It occurred to me recently that maybe we could make "function" and "fn" synonyms everywhere, i.e. make both "$double = function($x) => $x *2;" and "$double = fn($x) use ($x) { return $x *2; };" valid. I'm not sure if that's desirable, or even if there's a reason it can't be done, but it would mean you don't have to make a decision on this RFC... Regards, -- Rowan Tommins (né Collins) [IMSoP]

« previous php.internals (#112098) next »