Skip to content

Commit 047ba01

Browse files
committed
Add section on enumerations.
1 parent 8201676 commit 047ba01

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
@@ -1076,6 +1076,36 @@ $instance = new class extends \Foo implements
10761076
};
10771077
~~~
10781078

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

0 commit comments

Comments
 (0)