1 | <?php |
||
8 | abstract class Enum extends MyCLabsEnum |
||
9 | { |
||
10 | /** |
||
11 | * Default enum value. |
||
12 | */ |
||
13 | const __default = null; |
||
14 | |||
15 | /** |
||
16 | * {@inheritdoc} |
||
17 | */ |
||
18 | 42 | public function __construct($value = null) |
|
26 | |||
27 | 3 | public static function randomKey(): string |
|
33 | |||
34 | 3 | public static function randomValue(): string |
|
40 | |||
41 | 6 | public function label(): string |
|
45 | |||
46 | 3 | public static function labels(): array |
|
56 | |||
57 | 9 | private static function getLabel(string $value): string |
|
68 | |||
69 | 9 | public function is($value) |
|
77 | |||
78 | 3 | public function isAny(iterable $values) |
|
88 | |||
89 | 87 | public static function toArray(bool $include_default = false): array |
|
99 | |||
100 | /** |
||
101 | * Returns all consts (possible values) as an array according to `SplEnum` class. |
||
102 | */ |
||
103 | 6 | public function getConstList(bool $include_default = false): array |
|
107 | |||
108 | /** |
||
109 | * Returns the validation rule (to validate by value). |
||
110 | * |
||
111 | * @return EnumRule |
||
112 | */ |
||
113 | 6 | public static function rule(): EnumRule |
|
117 | |||
118 | /** |
||
119 | * Returns the validation rule (to validate by key). |
||
120 | * |
||
121 | * @return EnumRule |
||
122 | */ |
||
123 | 6 | public static function ruleByKey(): EnumRule |
|
127 | } |
||
128 |
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: