Re: Primary Constructors
| From: | Larry Garfield | Date: | Mon, 22 Jun 2026 18:49:50 +0000 |
| Subject: | Re: Primary Constructors | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-131476@lists.php.net to get a copy of this message | ||
On Mon, Jun 22, 2026, at 1:40 PM, Tim Düsterhus wrote:
> Hi
>
> Am 2026-06-22 17:15, schrieb Larry Garfield:
>> I don't think we should include the "secondary constructor calls
>> primary constructor and you have to make sure it works" logic.
>
> PHP doesn't (and cannot easily) support method overloading, thus there
> cannot be such a thing as “primary and secondary” constructor. It is
> unclear to me what you are getting at here.
That we shouldn't do that part. :-) I was showing what Kotlin does, and calling out the parts
we should and should not consider stealing.
>> However, I do think we can/should consider an init block.
>
> At the point where extra logic is required maybe just write a plain old
> regular __construct() method instead of inventing yet another
> “method-like” construct.
>
> Best regards
> Tim Düsterhus
Allowing a __construct() method with no arguments when a "primary constructor" is in use
would be fine with me, if that's the way we decide to go.
--Larry Garfield