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 | 39 | 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 | 6 | public function is($value) |
|
70 | { |
||
71 | 6 | return $this->getValue() === ($value instanceof self ? $value->getValue() : $value); |
|
72 | } |
||
73 | |||
74 | 81 | public static function toArray(bool $include_default = false): array |
|
84 | |||
85 | /** |
||
86 | * Returns all consts (possible values) as an array according to `SplEnum` class. |
||
87 | */ |
||
88 | 6 | public function getConstList(bool $include_default = false): array |
|
92 | |||
93 | /** |
||
94 | * Returns the validation rule (to validate by value). |
||
95 | * |
||
96 | * @return EnumRule |
||
97 | */ |
||
98 | 6 | public static function rule(): EnumRule |
|
102 | |||
103 | /** |
||
104 | * Returns the validation rule (to validate by key). |
||
105 | * |
||
106 | * @return EnumRule |
||
107 | */ |
||
108 | 6 | public static function ruleByKey(): EnumRule |
|
112 | } |
||
113 |
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: