%s %s contains %d abstract method%s and must therefore be declared abstract or implement the remaining method%s (

Description

A class (or a trait, once it is used in a class) that does not provide a body for one or more of its abstract methods – inherited from a parent class, or required by an implemented interface – must itself be declared abstract. Otherwise PHP has no concrete implementation to call when the method is invoked, and it stops with a fatal error while linking the class.

The message lists every abstract method that is still missing a concrete implementation, up to three of them; when there are more, the list ends with ....

This is the templated, general-purpose version of the message: the first %s is replaced by the kind of structure (Class or Interface), the second by its name.

Since PHP 8.5, enums and anonymous classes no longer use this message: they get the dedicated %s %s must implement %d abstract method%s (...) message instead, since neither of them can be declared abstract.

Example

<?php

interface Colorful {
    function color();
}

class Suit implements Colorful {
}

?>

Literal Examples

  • Class Suit contains 1 abstract method and must therefore be declared abstract or implement the remaining method (Colorful::color)

Solutions

  • Implement the missing method(s), with a body, in the class.

  • Declare the class abstract.

  • Remove the implements/extends clause that brings in the abstract method.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See Prior to PHP 8.5, ``method%s` and remaining method%s were always rendered in the plural, even when a single method was missing (see class-%s-contains-%d-abstract-method%s-and-must-therefore-be-declared-abstract-or-implement-the-remaining-methods). Prior to PHP 8.5, anonymous classes and enums also used this message; they now use %s %s must implement %d abstract method%s (...) instead. <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/Prior to PHP 8.5, method%s and remaining method%s were always rendered in the plural, even when a single method was missing (see class-%s-contains-%d-abstract-method%s-and-must-therefore-be-declared-abstract-or-implement-the-remaining-methods). Prior to PHP 8.5, anonymous classes and enums also used this message; they now use %s %s must implement %d abstract method%s (...) instead..html>`_.