PHP/native/BackedEnum

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< PHP
Revision as of 13:34, 25 August 2024 by Woozle (talk | contribs)
Jump to navigation Jump to search
BackedEnum pseudointerface
manual page: The BackedEnum interface

Note that this (pseudo)interface cannot actually be implemented as a standard class; it can only be (pseudo)implemented by declaring a backed enum.

Definition

interface BackedEnum extends UnitEnum {

   static from(int|string $value): static;
   static tryFrom(int|string $value): ?static;

   string|int $value; // pseudocode

   // INHERITED from UnitEnum (unmodified):

   static cases(): array;
   string $name; // pseudocode
}

The member-variables are labelled "pseudocode" because a normal interface can't declare member-variables.