website/errors/enumImplements.enum.md
<?php declare(strict_types = 1);
enum Color
{
case Red;
}
enum Shape implements Color
{
case Circle;
}
An enum uses implements to reference another enum instead of an interface. In PHP, enums can only implement interfaces. An enum cannot implement another enum.
If both enums need to share a common contract, create an interface:
<?php declare(strict_types = 1);
+interface HasLabel
+{
+ public function label(): string;
+}
+
-enum Color
+enum Color implements HasLabel
{
case Red;
+
+ public function label(): string
+ {
+ return $this->name;
+ }
}
-enum Shape implements Color
+enum Shape implements HasLabel
{
case Circle;
+
+ public function label(): string
+ {
+ return $this->name;
+ }
}