1 | <?php |
||
10 | abstract class Enum extends MyCLabsEnum implements CastsAttributes |
||
11 | { |
||
12 | use EnumCastable; |
||
13 | |||
14 | /** |
||
15 | * Default enum value. |
||
16 | */ |
||
17 | const __default = null; |
||
18 | 42 | ||
19 | /** |
||
20 | 42 | * {@inheritdoc} |
|
21 | 18 | */ |
|
22 | public function __construct($value = null) |
||
30 | |||
31 | 3 | public static function randomKey(): string |
|
37 | |||
38 | 3 | public static function randomValue(): string |
|
44 | |||
45 | public function label(): string |
||
49 | |||
50 | 3 | public static function labels(): array |
|
60 | 9 | ||
61 | 9 | private static function getLabel(string $value): string |
|
72 | 3 | ||
73 | public function is($value) |
||
81 | 3 | ||
82 | 3 | public function isAny(iterable $values) |
|
92 | |||
93 | 87 | public static function toArray(bool $include_default = false): array |
|
103 | 6 | ||
104 | /** |
||
105 | 6 | * Returns all consts (possible values) as an array according to `SplEnum` class. |
|
106 | */ |
||
107 | public function getConstList(bool $include_default = false): array |
||
111 | |||
112 | /** |
||
113 | 6 | * Returns the validation rule (to validate by value). |
|
114 | * |
||
115 | 6 | * @return EnumRule |
|
116 | */ |
||
117 | public static function rule(): EnumRule |
||
121 | |||
122 | /** |
||
123 | 6 | * Returns the validation rule (to validate by key). |
|
124 | * |
||
125 | 6 | * @return EnumRule |
|
126 | */ |
||
127 | public static function ruleByKey(): EnumRule |
||
131 | } |
||
132 |
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: