Difference between revisions of "PHP/enum"

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
Line 32: Line 32:
 
To get a UnitEnum enum from a case name (equivalent to from()/tryFrom()):
 
To get a UnitEnum enum from a case name (equivalent to from()/tryFrom()):
 
* constant("{{arg|enum name}}::{$value}")
 
* constant("{{arg|enum name}}::{$value}")
 +
==Tests==
 +
* is an <code>enum</code> an object (<code>is_object</code>)? [YES]
 +
* is an <code>enum</code> seen as <code>is_a UnitEnum</code>? [YES]
 +
* is an <code>enum</code> an <code>instanceof UnitEnum</code>? [YES]
 +
* is an <code>enum</code> an <code>instanceof enum</code>? [no]

Revision as of 20:42, 11 April 2023

PHP enum support

Methods

kind of thing name returns defined in
static function cases() array UnitEnum
static function final tryFrom(int or string $value) ?static BackedEnum
static function final from(int or string $value) static BackedEnum
dynamic property $name string (UnitEnum)
dynamic property $value int or string (BackedEnum)

Documentation

official

3rd party

Sample Code

To get a UnitEnum enum from a case name (equivalent to from()/tryFrom()):

  • constant("<enum name>::{$value}")

Tests

  • is an enum an object (is_object)? [YES]
  • is an enum seen as is_a UnitEnum? [YES]
  • is an enum an instanceof UnitEnum? [YES]
  • is an enum an instanceof enum? [no]