Re: [RFC] Primary Constructors

From: Date: Wed, 01 Jul 2026 13:44:10 +0000
Subject: Re: [RFC] Primary Constructors
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-131656@lists.php.net to get a copy of this message
On Mon, 29 Jun 2026 at 01:18, Rob Landers <rob@getswytch.com> wrote: > Hello internals, > > I'd like to put forward Primary Constructors > <https://wiki.php.net/rfc/primary-constructors> for > comment. > > An implementation PR will be opened later today (UTC), and the RFC updated > with this discussion thread. > > — Rob > I think this would be a great addition to PHP. There has been a few times in my career where I have needed to extend a 3rd party library and calling parent::__construct($params); at the end of my extending class always felt dirty. Being able to use ``` class MyClass(int arg1, string $arg2) extends Base(string $arg2) {} ``` Is much better, and clearer. It can avoid mistakes where a developer extends a class, doesnt call the parent constructor, it works but the base class might not be correctly initialized and might break down the line in production. Having an explicit "this get passed to the class we are extended" in the definition would wipe out that headache area.

« previous php.internals (#131656) next »