Re: Short Function Syntax

From: Date: Thu, 02 Nov 2023 20:03:26 +0000
Subject: Re: Short Function Syntax
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-121557@lists.php.net to get a copy of this message
> I know that the fn Syntax is already used for arrow functions, > but what i > am suggesting is that, can't we make fn to be used in > naming methods in > class? (this will be optional though), Hello Oladoyinbo, Personally for me, if I see fn in methods instead of function I would expect it behave as fn-anonymous arrow function. E.g.: ```php class Example { public fn getMyProperty() -> $this->myProperty; } ``` What do you think about it? Best regards, Oleksii Bulba On Thu, 2 Nov 2023, 21:31 Oladoyinbo Vincent, <oladoyinbov@gmail.com> wrote: > Hello Internals, > > I don't know maybe this discussion has been raised before, but i feel we > should re-discuss this. > > function syntax is kinda verbose for naming methods in class, > let's take > a look at the below example: > > > ```php > > class Greet { > > public function __construct( > private string $name, > private string $city > ) {} > > private function init(): string > { > return "Hello {$this->name}, From {$this->city}"; > } > } > > ``` > > I know that the fn Syntax is already used for arrow functions, > but what i > am suggesting is that, can't we make fn to be used in > naming methods in > class? (this will be optional though), > > > I mean like: > > ```php > > class Greet { > > public fn __construct( > public string $name, > public string $city > ) {} > > private fn init(): string > { > return "Hello {$this->name}, From {$this->city}"; > } > } > > ``` > > The above code looks cool, readable and less verbose, what is your opinion > on this? >

« previous php.internals (#121557) next »