PHP/native/UnitEnum: Difference between revisions

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< PHP
No edit summary
No edit summary
Line 1: Line 1:
{{fmt/title|UnitEnum pseudointerface}}
{{fmt/title|UnitEnum pseudointerface|'''manual page''': [https://www.php.net/manual/en/class.unitenum.php The UnitEnum interface]}}
* '''manual page''': [https://www.php.net/manual/en/class.unitenum.php The UnitEnum interface]


Note that this cannot actually be implemented as a class, except by declaring a backed enum.
Note that this interface cannot actually be implemented as a standard class; it can only be (pseudo)implemented by declaring an {{l/php|enum}}.
 
If an enum is "backed" (declared as having a scalar value for each choice), it will implement this interface but also the {{l/same|BackedEnum}} interface.)
==Definition==
==Definition==
<syntaxhighlight lang=php>
<syntaxhighlight lang=php>
interface UnitEnum {
interface UnitEnum {
   static cases(): array
   static function cases(): array
   string $name; // unofficial
 
   string $name; // pseudocode
}
}
</syntaxhighlight>
</syntaxhighlight>

Revision as of 12:51, 25 August 2024

UnitEnum pseudointerface
manual page: The UnitEnum interface

{{#set: page title=UnitEnum pseudointerface }}

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

If an enum is "backed" (declared as having a scalar value for each choice), it will implement this interface but also the BackedEnum interface.)

Definition

interface UnitEnum {
  static function cases(): array

  string $name; // pseudocode
}