Glossary

Enum (Enumeration)

An enum (enumeration) is a data type with a fixed set of named constants. Instead of "magic" strings like 'published', 'draft' throughout the code — a type with compile-time checking. PHP supports enums since version 8.1.

Backed Enum (with type)

enum Status: string {
  case Draft     = 'draft';
  case Published = 'published';
  case Archived  = 'archived';
}

$post->status = Status::Published;
echo Status::Published->value; // "published"
$s = Status::from('draft');    // Status::Draft

Pure Enum (no type)

enum Direction {
  case North; case South; case East; case West;
}

Benefits