Skip to content

EnumTrait ​

trait · pocketmine\utils\EnumTrait · source

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() ​

php
public function equals(self $other) : bool

Returns whether the two objects are equivalent.

getAll() ​

php
public static function getAll() : array

Returns all members of the enum. This is overridden to change the return typehint.

id() ​

php
public function id() : int

Returns 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() ​

php
public function name() : string

register() protected ​

php
protected static function register(self $member) : void

Registers the given object as an enum member.

registerAll() protected ​

php
protected static function registerAll(self ...$members) : void

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.