Skip to content

Commit 10c5285

Browse files
committed
Add section on enumerations.
1 parent b15e995 commit 10c5285

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

spec.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,36 @@ $instance = new class extends \Foo implements
10811081
};
10821082
```
10831083

1084+
## 9. Enumerations
1085+
1086+
Enumerations MUST follow the same guidelines as classes, except where otherwise noted here.
1087+
1088+
Methods in Enumerations MUST follow the same guidelines as methods in classes. Non-public methods MUST use `private`
1089+
instead of `protected`.
1090+
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.
1093+
1094+
Enumeration cases MUST use CamelCase capitalization.
1095+
1096+
Constants in Enumerations MAY use either CamelCase or UPPER_CASE capitalization. CamelCase is RECOMMENDED,
1097+
so that it is consistent with cases.
1098+
1099+
No more than one case is permitted per line.
1100+
1101+
```php
1102+
enum Suit: string
1103+
{
1104+
case Hearts = 'H';
1105+
case Diamonds = 'D';
1106+
case Spades = 'S';
1107+
case Clubs = 'C';
1108+
1109+
const Wild = self::Spades;
1110+
}
1111+
1112+
```
1113+
10841114
[PSR-1]: https://www.php-fig.org/psr/psr-1/
10851115
[PSR-12]: https://www.php-fig.org/psr/psr-12/
10861116
[keywords]: http://php.net/manual/en/reserved.keywords.php

0 commit comments

Comments
 (0)