Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Only hooked properties may be declared abstract

Description

Hooked properties may be declared abstract, as long as the class is also abstract, and that one of the hook, get or set or both, have no body block.

In previous version, PHP would never allow properties to be abstract.

Example

<?php

    abstract class X {
        public abstract string $x;
    }

?>

Alternatives

  • Add an identity hook to the class, such as get => $this->x or set => $this->x = $value;.
  • Remove the abstract keyword.

In previous PHP versions, this error message used to be :ref:cannot-use-the-abstract-modifier-on-a-property.