|
Basic enumerationsEnums are similar to classes, and share the same namespaces as classes, interfaces, and traits. They are also autoloadable the same way. An Enum defines a new type, which has a fixed, limited number of possible legal values.
This declaration creates a new enumerated type named
An Enumeration may have zero or more For Enumeration cases, the same syntax rules apply as to any label in PHP, see Constants.
By default, cases are not intrinsically backed by a scalar value. That is,
It also means that enum values are never This type of case, with no related data, is called a "Pure Case." An Enum that contains only Pure Cases is called a Pure Enum. All Pure Cases are implemented as instances of their enum type. The enum type is represented internally as a class.
All Cases have a read-only property, It is also possible to use the defined and constant functions to check for the existence of or read an enum case if the name is obtained dynamically. This is, however, discouraged as using Backed enums should work for most use cases. |