0PricingLogin
PHP Academy · Lesson

Enumerations (Enums)

Define type-safe sets of values with PHP 8.1 backed and pure enums.

What Are Enums?

PHP 8.1 introduced enums — a special type that restricts a variable to a predefined set of named values, making code more expressive and type-safe.

Pure Enum (Unit Enum)

A pure enum has named cases with no associated value. Great for state, direction, or status.

<?php
enum Status {
    case Active;
    case Inactive;
    case Banned;
}

$s = Status::Active;
echo $s->name; // "Active"

All lessons in this course

  1. Match Expression and Named Arguments
  2. Nullsafe Operator and Union Types
  3. Enumerations (Enums)
  4. Fibers: Cooperative Concurrency
← Back to PHP Academy