Enumeration

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;
}

?>

Documentation

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, On the use of enums

Related : Enumeration Case, Collection

Related packages : myclabs/php-enum, dasprid/enum, spatie/enum

Added in PHP 8.1+