Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add section on enumerations. #7

Merged
merged 6 commits into from
Jul 17, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ class Foo extends Bar implements FooInterface
// method body
}
}

Enum Beep: int
{
case Foo = 1;
case Bar = 2;

public function isOdd(): bool
{
return $this->value() % 2;
}
}
```

## 2. General
Expand Down Expand Up @@ -233,7 +244,7 @@ declare(ticks=1) {

## 4. Classes, Properties, and Methods

The term "class" refers to all classes, interfaces, and traits.
The term "class" refers to all classes, interfaces, traits, and enums.

Any closing brace MUST NOT be followed by any comment or statement on the
same line.
Expand Down Expand Up @@ -1081,6 +1092,34 @@ $instance = new class extends \Foo implements
};
```

## 9. Enumerations

Enumerations (enums) MUST follow the same guidelines as classes, except where otherwise noted below.

Methods in enums MUST follow the same guidelines as methods in classes. Non-public methods MUST use `private`
instead of `protected`, as enums do not support inheritance.

When using a backed enum, there MUST NOT be a space between the enum name and colon, and there MUST be exactly one
space between the colon and the backing type. This is consistent with the style for return types.

Enum case declarations MUST use CamelCase capitalization. Enum case declarations MUST be on their own line.

Constants in Enumerations MAY use either CamelCase or UPPER_CASE capitalization. CamelCase is RECOMMENDED,
so that it is consistent with case declarations.

```php
enum Suit: string
{
case Hearts = 'H';
case Diamonds = 'D';
case Spades = 'S';
case Clubs = 'C';

const Wild = self::Spades;
}

```

[PSR-1]: https://www.php-fig.org/psr/psr-1/
[PSR-12]: https://www.php-fig.org/psr/psr-12/
[keywords]: http://php.net/manual/en/reserved.keywords.php
Expand Down