Backed Enumeration¶
Backed enumerations are enumerations whose cases have a built-in scalar equivalent. The scalars may be integers or strings.
There are methods to convert a scalar value to an enumeration’s case, notably from() and tryFrom(). On the other way, the cases have a property called value
.
<?php
enum Suit: string
{
case Hearts = 'H';
case Diamonds = 'D';
case Clubs = 'C';
case Spades = 'S';
}
?>
Related : Enumeration (enum)
Added in PHP 8.1+