@@ -68,6 +68,17 @@ class Foo extends Bar implements FooInterface
68
68
// method body
69
69
}
70
70
}
71
+
72
+ Enum Beep: int
73
+ {
74
+ case A = 1;
75
+ case B = 2;
76
+
77
+ public function isOdd(): bool
78
+ {
79
+ return $this->value() % 2;
80
+ }
81
+ }
71
82
```
72
83
73
84
## 2. General
@@ -233,7 +244,7 @@ declare(ticks=1) {
233
244
234
245
## 4. Classes, Properties, and Methods
235
246
236
- The term "class" refers to all classes, interfaces, and traits .
247
+ The term "class" refers to all classes, interfaces, traits, and enums .
237
248
238
249
Any closing brace MUST NOT be followed by any comment or statement on the
239
250
same line.
@@ -1083,21 +1094,19 @@ $instance = new class extends \Foo implements
1083
1094
1084
1095
## 9. Enumerations
1085
1096
1086
- Enumerations MUST follow the same guidelines as classes, except where otherwise noted here.
1097
+ Enumerations (enums) MUST follow the same guidelines as classes, except where otherwise noted here.
1087
1098
1088
- Methods in Enumerations MUST follow the same guidelines as methods in classes. Non-public methods MUST use ` private `
1089
- instead of ` protected ` .
1099
+ Methods in enums MUST follow the same guidelines as methods in classes. Non-public methods MUST use ` private `
1100
+ instead of ` protected ` , as enums do not support inheritance .
1090
1101
1091
- In the case of a backed enum, there MUST NOT be a space between the enum name and colon, and there MUST be exactly one
1092
- space between the colon and the backing type.
1102
+ When using a backed enum, there MUST NOT be a space between the enum name and colon, and there MUST be exactly one
1103
+ space between the colon and the backing type. This is consistent with the style for return types.
1093
1104
1094
- Enumeration cases MUST use CamelCase capitalization.
1105
+ Enum case declarations MUST use CamelCase capitalization. Enum case declarations MUST be on their own line .
1095
1106
1096
1107
Constants in Enumerations MAY use either CamelCase or UPPER_CASE capitalization. CamelCase is RECOMMENDED,
1097
1108
so that it is consistent with cases.
1098
1109
1099
- No more than one case is permitted per line.
1100
-
1101
1110
``` php
1102
1111
enum Suit: string
1103
1112
{
0 commit comments