Enums Implementing Interfaces
TL;DR
PHP 8.1 enums can implement interfaces, allowing them to be used wherever an interface is expected — enabling polymorphic enum-based dispatch.
Explanation
Pure and backed enums can both implement interfaces. This enables: type-hinted parameters that accept enums (function process(Colorable $c)), enum cases used in collections alongside other objects implementing the same interface, and enum methods satisfying interface contracts. Enums cannot extend classes (they already extend UnitEnum/BackedEnum internally), but implementing multiple interfaces is allowed. Interface constants can be declared in enums too (PHP 8.3+). Common pattern: Status enum implementing HasLabel interface with getLabel() method.
Common Misconception
✗ Enums can extend classes — they can only implement interfaces. Enums already extend UnitEnum or BackedEnum internally.
Why It Matters
Interface-implementing enums enable clean polymorphism without class hierarchies — enum cases become first-class participants in interface contracts.
Common Mistakes
- Trying to extend a class with an enum — fatal error.
- Not declaring required interface methods in the enum body.
- Missing return types for interface methods in the enum implementation.
Code Examples
✗ Vulnerable
interface HasLabel {
public function getLabel(): string;
}
// Without interface — no type safety:
enum Status { case Active; case Inactive; }
function render($status) { /* no type hint */ }
✓ Fixed
interface HasLabel {
public function getLabel(): string;
}
enum Status: string implements HasLabel {
case Active = 'active';
case Inactive = 'inactive';
public function getLabel(): string {
return match($this) {
Status::Active => 'Active',
Status::Inactive => 'Inactive',
};
}
}
function renderBadge(HasLabel $item): string {
return '<span>' . $item->getLabel() . '</span>';
}
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
22 Mar 2026
Views
24
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 8
Unknown AI 3
Google 2
Perplexity 2
SEMrush 2
ChatGPT 1
Meta AI 1
Ahrefs 1
Also referenced
How they use it
crawler 19
pre-tracking 1
Related categories
⚡
DEV INTEL
Tools & Severity
🔵 Info
⚙ Fix effort: Low
⚡ Quick Fix
Add implements InterfaceName to enum declaration and implement all required methods using match($this) to dispatch per case.
📦 Applies To
PHP 8.1+
web
cli
queue-worker
🔗 Prerequisites
🔍 Detection Hints
enum .* {
Auto-detectable:
✗ No
phpstan
psalm
🤖 AI Agent
Confidence: Low
False Positives: High
✗ Manual fix
Fix: Medium
Context: Class
Tests: Update