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

PHP 8.5 split the missing-abstract-method message by declaration kind

A class, interface, enum, or anonymous class left with an unimplemented abstract method (inherited from a parent class, or required by an implemented interface) was reported with one generic message: “%s %s contains %d abstract method%s and must therefore be declared abstract or implement the remaining method%s (…)”. Enums were the only exception: they already had a dedicated message, “%s %s must implement %d abstract method%s (…)”, but its wording incorrectly said “abstract private method%s” even for methods that were not private.

PHP 8.5 gives enums and anonymous classes their own dedicated message, since neither of them can be declared abstract to defer the missing implementation the way an ordinary class can. Anonymous classes now use the same “must implement N abstract method(s)” message enums already had, and the enum wording drops the incorrect “private” word. Ordinary named classes and interfaces keep using the original generic “contains … must therefore be declared abstract or implement the remaining method(s)” message.

A related, third message, “%s method %s::%s() must not be abstract”, is raised when a method is explicitly marked abstract inside an interface (redundant, since interface methods are implicitly abstract) or, since PHP 8.5, inside an enum (which can never be declared abstract). Before 8.5, writing abstract directly on an enum method instead fell through to the generic “must implement N abstract method(s)” message.

PHP code

<?php

interface Colorful {
    function color();
}

enum Suit implements Colorful {
    case Hearts;
}

?>

Before

Fatal error: Enum Suit must implement 1 abstract private method (Colorful::color)

After

Fatal error: Enum Suit must implement 1 abstract method (Colorful::color)

PHP version change

This behavior changed in 8.5.

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat