Skip to content

Convert the first batch of Enums classes to PHP enums #612

Closed

Description

@armanist

Summary

Turn the constant classes in the Enums folders that can convert on PHP 8.1 into PHP enums. The adapter types and the remaining classes are in #620, planned for 3.2.0 with PHP 8.2.

Why

An enum gives a closed set of values that PHP and PHPStan check, instead of free strings and integers. A wrong value is caught by the type and not at runtime.

Classes in this ticket

These six are not used in any class constant, property default or parameter default, so nothing blocks them on PHP 8.1:

  • AuthKeys, ReservedKeys
  • the database Type, Key and Relation
  • Pagination

Things to handle

  • An enum case is not its value. Comparisons, array keys and parameters that use the value need ->value, and text that comes from outside needs ::from() or ::tryFrom().
  • AuthTrait reads AuthKeys with ReflectionClass::getConstants(); with an enum that becomes AuthKeys::cases().
  • Pagination mixes string and integer values, and a backed enum has to be all strings or all integers. Decide how to represent it when it is converted.
  • Relation is used in application models ('type' => Relation::BELONGS_TO), in the docs and in the starter project, so update them in step.

Out of scope

Breaking changes

  • Public constants become enum cases, and the type of some public parameters and return values changes. To be listed in the changelog.

Acceptance criteria

  • each class above is converted, or has a recorded reason to stay a constants class
  • the starter project, the module templates and the docs examples use the new form
  • composer test, composer cs:check, composer phpstan and composer rector:check pass on every PHP version in the CI matrix
  • the changelog lists every converted class

Activity

  1. added this to the 3.1.1 milestone on Oct 24, 2026
  2. changed the title [-]Convert the constant classes in the Enums folders to PHP enums[/-] [+]Convert the first batch of Enums classes to PHP enums[/+] on Oct 26, 2026
  3. added 9 commits that reference this issue on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions