@@ -68,6 +68,17 @@ class Foo extends Bar implements FooInterface
6868 // method body
6969 }
7070}
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+ }
7182```
7283
7384## 2. General
@@ -274,7 +285,7 @@ declare(ticks=1) {
274285
275286## 4. Classes, Properties, and Methods
276287
277- The term "class" refers to all classes, interfaces, and traits .
288+ The term "class" refers to all classes, interfaces, traits, and enums .
278289
279290Any closing brace MUST NOT be followed by any comment or statement on the
280291same line.
@@ -1165,7 +1176,33 @@ $instance = new class extends \Foo implements
11651176};
11661177```
11671178
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
11691206
11701207A nowdoc SHOULD be used wherever possible. Heredoc MAY be used when a nowdoc
11711208does not satisfy requirements.
0 commit comments