@@ -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 Foo = 1;
75
+ case Bar = 2;
76
+
77
+ public function isOdd(): bool
78
+ {
79
+ return $this->value() % 2;
80
+ }
81
+ }
71
82
```
72
83
73
84
## 2. General
@@ -274,7 +285,7 @@ declare(ticks=1) {
274
285
275
286
## 4. Classes, Properties, and Methods
276
287
277
- The term "class" refers to all classes, interfaces, and traits .
288
+ The term "class" refers to all classes, interfaces, traits, and enums .
278
289
279
290
Any closing brace MUST NOT be followed by any comment or statement on the
280
291
same line.
@@ -1165,7 +1176,33 @@ $instance = new class extends \Foo implements
1165
1176
};
1166
1177
```
1167
1178
1168
- ## 9. Heredoc and Nowdoc
1179
+ ## 9. Enumerations
1180
+
1181
+ Enumerations (enums) MUST follow the same guidelines as classes, except where otherwise noted below.
1182
+
1183
+ Methods in enums MUST follow the same guidelines as methods in classes. Non-public methods MUST use ` private `
1184
+ instead of ` protected ` , as enums do not support inheritance.
1185
+
1186
+ When using a backed enum, there MUST NOT be a space between the enum name and colon, and there MUST be exactly one
1187
+ space between the colon and the backing type. This is consistent with the style for return types.
1188
+
1189
+ Enum case declarations MUST use CamelCase capitalization. Enum case declarations MUST be on their own line.
1190
+
1191
+ Constants in Enumerations MAY use either PascalCase or UPPER_CASE capitalization. PascalCase is RECOMMENDED,
1192
+ so that it is consistent with case declarations.
1193
+
1194
+ ``` php
1195
+ enum Suit: string
1196
+ {
1197
+ case Hearts = 'H';
1198
+ case Diamonds = 'D';
1199
+ case Spades = 'S';
1200
+ case Clubs = 'C';
1201
+
1202
+ const Wild = self::Spades;
1203
+ }
1204
+
1205
+ ## 10. Heredoc and Nowdoc
1169
1206
1170
1207
A nowdoc SHOULD be used wherever possible. Heredoc MAY be used when a nowdoc
1171
1208
does not satisfy requirements.
0 commit comments