Enumeration (enum)¶
Enumerations are a restricting layer on top of classes and class constants, intended to provide a way to define a closed set of possible values for a type.
<?php
enum Suit
{
case Hearts;
case Diamonds;
case Clubs;
case Spades;
}
?>
See also Enumerations in PHP, 5 Pitfalls of Upgrade to Native PHP Enums and How to Avoid Them, On the use of enums, Enum in PHP — Real life examples
Related : Enumeration Case, Collection, Class Interface Trait Enumeration (CITE)
Related packages : myclabs/php-enum, dasprid/enum, spatie/enum
Added in PHP 8.1+