PHP 8.0 added constructor promotion, which turns constructor parameters into properties. This RFC from Robert Landers takes the next step: you'd put the constructor's parameters right after the class name and skip the __construct() method entirely.

Show me

Today you write this:

class Money {
    public function __construct(
        public readonly int $amount,
        public readonly string $currency = 'USD',
    ) {}
}

With this RFC, you could write this instead:

class Money(
    public readonly int $amount,
    public readonly string $currency = 'USD',
) {}

The two are exactly equivalent. The parameter list in the header is the constructor.

How it works

A parameter marked public, protected, private or readonly becomes a property, just like promotion today. A parameter with no modifier stays a plain parameter that only exists while the object is being built.

Plain parameters are handy for passing values up to a parent class. Since there's no method body, you can't call parent::__construct(), so you put the arguments after extends instead:

class Dog(
    public string $breed,
    string $name,
) extends Animal($name) {}

extends Animal($name) calls the parent constructor with $name. Without the parentheses, no parent constructor runs, which matches how PHP behaves today.

There's no place for other constructor logic. To validate a value, you'd use a set hook on the parameter, and a class that needs more than that should keep a normal __construct().

A few more rules:

  • You can't declare both a primary constructor and __construct(). That's a fatal error.
  • They work on normal, abstract, final and readonly classes.
  • They aren't allowed on interfaces, enums, traits or anonymous classes.
  • Reflection is unchanged, and getConstructor() returns the generated constructor.

What it means for existing code

Nothing breaks. The RFC adds no new keywords, and the new syntax is a parse error today, so no working code uses it. IDEs, static analyzers and code formatters will need updates to understand it.

Where it stands

The RFC is under discussion on the internals mailing list, and no vote has started. It targets the next PHP 8.x release. Two open questions remain: whether PHP should warn when you leave out a required parent constructor call, and whether a later RFC should add a separate way to run setup code.