An Enum With An Interface¶
<?php
interface i {}
enum A1 implements i {
case A;
case B;
}
enum A2 implements i {
case C;
case D;
}
function foo(i $e) {
var_dump($e);
}
foo(A1::A);
foo(A2::C);
It is possible for an enumeration to implement an interface, even a marker interface. That way, it may group several enumerations together, to behave as one.
Obviously, conditions apply to do it, and, in the end, it is merely a short version of an union type. Readability may apply.
See Also¶
Enum with Interface [Try me]
PHP Features¶
Last updated: 13 August 2026