%s method %s::%s() must not be abstract

Description

Interface methods are implicitly abstract: they never carry a body, since an interface only declares a contract. Writing the abstract keyword explicitly on an interface method is therefore redundant, and PHP rejects it.

The same message is used for enums, since 8.5: an enum can never be declared abstract, so none of its own methods can be abstract either (its cases are not classes that could provide the missing implementation).

This is the templated, general-purpose version of the message: the first %s is replaced by the kind of structure (Interface or Enum), the second and third by the class name and the method name.

Before PHP 8.5, declaring an abstract method directly inside an enum body produced the generic %s %s must implement %d abstract method%s (...) message instead of this dedicated one.

Example

<?php

interface Colorful {
    abstract function color();
}

?>

Literal Examples

  • Interface method Colorful::color() must not be abstract

  • Enum method Suit::foo() must not be abstract

Solutions

  • Remove the abstract keyword from the method declaration.

  • If the method needs a real implementation, give it a body instead of declaring it abstract.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See Since PHP 8.5, this dedicated message also applies to enums; before that, an abstract method declared directly in an enum triggered the generic ‘must implement N abstract method(s)’ message..