Difference between revisions of "PHP/native/BackedEnum"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< PHP
Jump to navigation Jump to search
(Created page with "{{fmt/title|BackedEnum pseudointerface}} * '''manual page''': [https://www.php.net/manual/en/class.backedenum.php The BackedEnum interface] Note that this cannot actually be...")
 
Line 1: Line 1:
{{fmt/title|BackedEnum pseudointerface}}
+
{{fmt/title|BackedEnum pseudointerface|'''manual page''': [https://www.php.net/manual/en/class.backedenum.php The BackedEnum interface]}}
* '''manual page''': [https://www.php.net/manual/en/class.backedenum.php The BackedEnum interface]
 
  
Note that this cannot actually be implemented as a class, except by declaring a backed enum.
+
Note that this (pseudo)interface cannot actually be implemented as a standard class; it can only be (pseudo)implemented by declaring a backed {{l/php|enum}}.
 
==Definition==
 
==Definition==
 
<syntaxhighlight lang=php>
 
<syntaxhighlight lang=php>
 
interface BackedEnum extends UnitEnum {
 
interface BackedEnum extends UnitEnum {
/* Methods */
+
 
 
   static from(int|string $value): static;
 
   static from(int|string $value): static;
 
   static tryFrom(int|string $value): ?static;
 
   static tryFrom(int|string $value): ?static;
  
   string|int $value; // unofficial
+
   string|int $value; // pseudocode
  
/* Inherited */
+
// Inherited from UnitEnum:
 
   static UnitEnum::cases(): array;
 
   static UnitEnum::cases(): array;
 
   static cases(): array;
 
   static cases(): array;
  
   string $name; // unofficial
+
   string $name; // pseudocode
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
The member-variables are labelled "pseudocode" because a normal interface can't declare member-variables.

Revision as of 12:54, 25 August 2024

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:
   static UnitEnum::cases(): array;
   static cases(): array;

   string $name; // pseudocode
}

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