Incompatible Promoted Readonly

<?php

class x {
    function __construct(protected readonly int $x) {
    }
}

class y extends x {
    function __construct(protected readonly int $x) {
        parent::__construct($x);
    }
}

new y(1);
// Fatal error: Uncaught Error: Cannot modify readonly property y::$x

class z extends x {
    function __construct(int $x) {
        parent::__construct($x);
    }
}

new z(1);
// OK

?>

Promoted properties allows the creation of properties directly from the constructor signature.

readonly properties are only written once, and cannot be written again.

When a promoted property is public or protected, it cannot be used in two constructor’s signature, as the first instance is immediately written, and cannot be changed again.

This doesn’t happen with private, which keeps the properties distinct in the class and its parent. This still may produce confusion.

It is then possible to only use one promoted property definition, and skip that parameter in the other constructor; or make the second a simple parameter, rather than a promoted property.

See Also

PHP Error Messages

PHP Features

Last updated: 14 July 2026