PHP theorytheory 0/50 · 0%
Fundamentals · medium

21. Enums

Type-safe fixed value sets.

PHP 8.1 introduced native enums declared with the enum keyword, supporting pure enums and backed enums (with int or string values). Enum cases are singleton instances accessed as EnumName::Case.

Enums can implement interfaces and define methods, making them more powerful than plain class constants for representing fixed sets of related values.

Check your understanding

  1. 1. Which PHP version introduced native enums?

  2. 2. What is a backed enum?