Re: RFC: Single-Expression functions

From: 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 [email protected] 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 hooks
public 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(...)
|>            func3(...) |> func4(...);
That looks like a callable assignment like you know $f = fn ($bar) => $this->bar + $bar; class Foo {
      private $bar;
      public function bar() = $f;
} that may confuse users, another argument for => -- Anton

Thread (11 messages)

« previous php.internals (#127434) next »