1 | <?php |
||
22 | abstract class AbstractEnum implements Enum |
||
23 | { |
||
24 | use ImmutabilityBehaviour; |
||
25 | |||
26 | /** |
||
27 | * Enum class constants map. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected static $enumConstantsMap = []; |
||
32 | |||
33 | /** |
||
34 | * Enum value. |
||
35 | * |
||
36 | * @var mixed |
||
37 | */ |
||
38 | private $value; |
||
39 | |||
40 | /** |
||
41 | * AbstractEnum constructor. |
||
42 | * |
||
43 | * @param mixed $value |
||
44 | * |
||
45 | * @throws InvalidEnumValueException |
||
46 | */ |
||
47 | final public function __construct($value) |
||
55 | |||
56 | /** |
||
57 | * Value based static constructor. |
||
58 | * |
||
59 | * @param string $value |
||
60 | * @param mixed[] $params |
||
61 | * |
||
62 | * @return self |
||
63 | */ |
||
64 | final public static function __callStatic(string $value, array $params) |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | final public function isEqualTo(Enum $enum): bool |
||
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | final public function getValue() |
||
98 | |||
99 | /** |
||
100 | * Check enum value validity. |
||
101 | * |
||
102 | * @param mixed $value |
||
103 | * |
||
104 | * @throws InvalidEnumValueException |
||
105 | */ |
||
106 | private function checkValue($value): void |
||
116 | |||
117 | /** |
||
118 | * Get list of valid enum values. |
||
119 | * |
||
120 | * @return array<string, mixed> |
||
121 | */ |
||
122 | private static function getValidValues(): array |
||
132 | |||
133 | /** |
||
134 | * {@inheritdoc} |
||
135 | * |
||
136 | * @return string[] |
||
137 | */ |
||
138 | final protected function getAllowedInterfaces(): array |
||
142 | } |
||
143 |
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: