Enumerations

An enumeration (enum, since PHP 8.1) defines a type with a finite set of named values. A "backed" enum associates a string or int value with each case, accessible via ->value and built with from or tryFrom. It makes states explicit and checked by typing.

Example

enum Statut: string {
  case Brouillon = 'draft';
  case Publie = 'published';
}

Related concepts

The whole glossary