Cannot declare promoted property in an abstract constructor

Description

It is not possible to use a promoted property in an abstract constructor. The promoted property is akin to concrete code (the property assignation), while the abstrat constructor has no body.

On the other hand, a child class may overwrite the constructor signature with a promoted property, so it is possible to define properties that way, but not on an abstract method.

In order to enforce a property, from an abstract class, the property must be defined out of the constructor.

Example

<?php

abstract class X {
     abstract function __construct(private string $a);
}

?>

Solutions

  • Remove the abstract from the constructor.

  • Define the property outside the construtor.

  • Check all children classes, so they all have the promoted property in their constructor definition.