Re: [PHP-DEV] [RFC] Primary Constructors

[email protected] ("Rob Landers")
Newsgroups php.internals
Message-ID <[email protected]>

On Mon, Jun 29, 2026, at 20:54, Seifeddine Gmati wrote:
> On Mon, 29 Jun 2026 at 01:18, Rob Landers <[email protected]> wrote:
> >
> > Hello internals,
> >
> > I'd like to put forward Primary Constructors for comment.
> >
> > An implementation PR will be opened later today (UTC), and the RFC updated with this discussion thread.
> >
> > — Rob
> 
> Hi Rob,
> 
> Personally, I really dislike this feature.

Sincerely, thank you for your opinion.

> 
> It adds a new syntax that increases the complexity of the PHP grammar,
> which is already quite complex, for no real advantage. It's just a
> slightly different way to write something the language already
> expresses.
> 
> It's also confusing to read. A line like:
> 
> ```
> class Foo(public int $a, public string $b) extends Base($a, $b) { ... }
> ```
> 
> jumps from class definition, to constructor definition, to class
> definition again (inheritance), to what is effectively a
> `parent::__construct()` call, and then back into the class body.
> That's a lot of distinct concepts packed into a single line, with no
> syntactic separation to signal the shift from one to the next.
> 
> Cheers,
> Seifeddine.

It's also the entire point of the feature ;) You open the file, and in two seconds, you know:

It defines two properties, type int and string, it calls parent::__construct with those two parameters.

Currently, you open the class, seek to the constructor, read it to understand if it even calls the parent constructor or not. Just like promoted properties, the cost is nominal, but now it is nearly ubiquitous in usage and saves a large amount of time in reading and writing classes. This feature seeks to do the same.

— Rob
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.