Re: Brainstorming idea: inline syntax for lexical (captured) variables

From: Date: Thu, 16 Mar 2023 22:06:05 +0000
Subject: Re: Brainstorming idea: inline syntax for lexical (captured) variables
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-119729@lists.php.net to get a copy of this message
On 16/03/2023 17:59, Nicolas Grekas wrote:
We could define the "use" as declaring + setting the properties before the constructor is called, if any. But I'm also fine making both constructs conflict: when there is a constructor, the boilerplate saved by the "use" becomes really low. No strong opinion either. There could be other factors to consider.
The main advantage of generating an actual constructor is that no change is needed to the shared object initialization code, which could be complex and even have performance impact. The only new logic would be in compiling the class entry and putting the arguments into the "new class(...)" statement. The more I think about it, the more I'm leaning to just blocking custom constructors, and saying you can either have the use() short-hand, or you can have custom initialization. Additional functionality can always be added in later if someone comes up with a clean implementation and a good use case. Regards, -- Rowan Tommins [IMSoP]

« previous php.internals (#119729) next »