Skip to content

Latest commit

 

History

History
395 lines (160 loc) · 4.32 KB

AbstractEnum.md

File metadata and controls

395 lines (160 loc) · 4.32 KB

AbstractEnum

  • Full name: \DASPRiD\Enum\AbstractEnum
  • This class is an Abstract class

Properties

name

private string $name

ordinal

private int $ordinal

values

private static array<string,array<string,static>> $values
  • This property is static.

allValuesLoaded

private static array<string,bool> $allValuesLoaded
  • This property is static.

constants

private static array<string,array> $constants
  • This property is static.

Methods

__construct

The constructor is private by default to avoid arbitrary enum creation.

private __construct(): mixed

When creating your own constructor for a parameterized enum, make sure to declare it as protected, so that the static methods are able to construct it. Avoid making it public, as that would allow creation of non-singleton enum instances.


__callStatic

Magic getter which forwards all calls to {@see self::valueOf()}.

final public static __callStatic(string $name, array $arguments): static
  • This method is static.

  • This method is final.

Parameters:

Parameter Type Description
$name string
$arguments array

valueOf

Returns an enum with the specified name.

final public static valueOf(string $name): static

The name must match exactly an identifier used to declare an enum in this type (extraneous whitespace characters are not permitted).

  • This method is static.

  • This method is final.

Parameters:

Parameter Type Description
$name string

createValue

private static createValue(string $name, int $ordinal, array $arguments): static
  • This method is static.

Parameters:

Parameter Type Description
$name string
$ordinal int
$arguments array

values

Obtains all possible types defined by this enum.

final public static values(): static[]
  • This method is static.

  • This method is final.


constants

private static constants(): array
  • This method is static.

name

Returns the name of this enum constant, exactly as declared in its enum declaration.

final public name(): string

Most programmers should use the {@see} method in preference to this one, as the toString method may return a more user-friendly name. This method is designed primarily for use in specialized situations where correctness depends on getting the exact name, which will not vary from release to release.

  • This method is final.

ordinal

Returns the ordinal of this enumeration constant (its position in its enum declaration, where the initial constant is assigned an ordinal of zero).

final public ordinal(): int

Most programmers will have no use for this method. It is designed for use by sophisticated enum-based data structures.

  • This method is final.

compareTo

Compares this enum with the specified object for order.

final public compareTo(self $other): int

Returns negative integer, zero or positive integer as this object is less than, equal to or greater than the specified object.

Enums are only comparable to other enums of the same type. The natural order implemented by this method is the order in which the constants are declared.

  • This method is final.

Parameters:

Parameter Type Description
$other self

__clone

Forbid cloning enums.

final public __clone(): mixed
  • This method is final.

__sleep

Forbid serializing enums.

final public __sleep(): array
  • This method is final.

__wakeup

Forbid unserializing enums.

final public __wakeup(): void
  • This method is final.

__toString

Turns the enum into a string representation.

public __toString(): string

You may override this method to give a more user-friendly version.