Abstract property %s::$%s must specify at least one abstract hook

Description

An abstract property must have at least one of its hooks declared without a body (abstract). If all hooks have implementations, the property cannot be abstract, as there is nothing left for child classes to implement.

This is a PHP 8.4 language-level restriction enforced for abstract properties with hooks. An abstract property’s purpose is to require child classes to provide an implementation, but if all hooks already have bodies, there is no requirement to fulfill.

Example

<?php

abstract class X {
    abstract public string $property {
        get { return ''; }
        set { }
    }
}

?>

Literal Examples

  • Abstract property x::$property must specify at least one abstract hook

Solutions

  • Make at least one hook abstract by removing its body block, e.g. change get { return ''; } to get;.

  • Remove the abstract keyword from the property if all hooks should have implementations.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.

Static Analysis

This error may be tracked down with the following static analysis rules: property.abstractWithoutAbstractHook.