Re: RFC: Single-Expression functions
| From: | Anton Smirnov | Date: | Fri, 23 May 2025 01:53:54 +0000 |
| Subject: | Re: RFC: Single-Expression functions | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-127434@lists.php.net to get a copy of this message | ||
Hi Dmitriy
On 22/05/2025 12:24, Dmitry Derepko wrote:
I'm aware that Larry Garfield previously proposed a similar feature several years ago, though it unfortunately didn't pass the voting stage. I would like to respectfully suggest that using "=" instead of "=>" to separate declaration and implementation might be a better approach. That looks like the weakest part of the proposition because we already have two places where inline bodies are used: the mentioned arrow functions and property hookspublic string $foo { get => 'dynamic value'; } No sense in introducing a new syntax for basically just another case of inline function body.
// oneline function handle(string $input): string = func1($input) |> func2(...)That looks like a callable assignment like you know $f = fn ($bar) => $this->bar + $bar; class Foo {|> func3(...) |> func4(...);
private $bar;
public function bar() = $f;} that may confuse users, another argument for => -- Anton