Cannot use the abstract modifier on a property¶
Description¶
Properties cannot be abstract, as they are always available in the class where they are defined.
This will change in PHP 8.4, with property hooks and abstract hooks. Until then, abstract properties are not valid.
Example¶
<?php
abstract class X {
public abstract string $x;
}
?>
Solutions¶
Upgrade to PHP 8.4, and use hooked properties.
Remove the abstract keyword.
Use magic methods
__get
and__set
to define a custom alternative property.
In more recent PHP versions, this error message is now Only hooked properties may be declared abstract.