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 $enumCacheMap = []; |
||
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 isAnyOf(array $enums): bool |
||
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | final public function getValue() |
||
112 | |||
113 | /** |
||
114 | * Check enum value validity. |
||
115 | * |
||
116 | * @param mixed $value |
||
117 | * |
||
118 | * @throws InvalidEnumValueException |
||
119 | */ |
||
120 | private function checkValue($value): void |
||
130 | |||
131 | /** |
||
132 | * Get list of valid enum values. |
||
133 | * |
||
134 | * @return array<string, mixed> |
||
135 | */ |
||
136 | private static function getValidValues(): array |
||
146 | |||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | * |
||
150 | * @return string[] |
||
151 | */ |
||
152 | final protected function getAllowedInterfaces(): array |
||
156 | } |
||
157 |
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: