EnumTrait
Deprecated
Use native PHP 8.1 enums instead. Use LegacyEnumShimTrait if you need to provide backwards
This trait allows a class to simulate a Java-style enum. Members are exposed as static methods and handled via __callStatic().
Classes using this trait need to include @method tags in their class docblock for every enum member. Alternatively, just put @generate-registry-docblock in the docblock and run build/codegen/registry-annotations.php
Methods
equals()
public function equals(self $other) : boolReturns whether the two objects are equivalent.
getAll()
public static function getAll() : arrayReturns all members of the enum. This is overridden to change the return typehint.
id()
public function id() : intReturns a runtime-only identifier for this enum member. This will be different with each run, so don't try to hardcode it. This can be useful for switches or array indexing.
name()
public function name() : stringregister() protected
protected static function register(self $member) : voidRegisters the given object as an enum member.
registerAll() protected
protected static function registerAll(self ...$members) : void