PHP/enum
from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< PHP
|
PHP enum support
|
{{#set: page title=PHP enum support }}
Methods
| kind of thing | name | args | returns | defined in | description |
|---|---|---|---|---|---|
| static function | cases | () |
array | UnitEnum | |
| static function final | tryFrom | (int|string $value) |
?static | BackedEnum | |
| static function final | from | (int|string $value) |
static | BackedEnum | |
| dynamic property | $name | string | (UnitEnum) | ||
| dynamic property | $value | int or string | (BackedEnum) | the name of the case (caps are preserved) |
Documentation
official
- Enumerations:
- Basic:
- Backed:
3rd party
Sample Code
To get a UnitEnum enum from a case name (equivalent to from()/tryFrom()):
- constant("<enum name>::{$value}")
Tests
- is an
enuman object (is_object)? [YES] - is an
enumseen asis_a UnitEnum? [YES] - is an
enumaninstanceof UnitEnum? [YES] - is an
enumaninstanceof enum? [no]
