Take the State of PHP 2026 Survey →

Algebraic data types (Meta RFC) View as Markdown

Inactive
Authors
Larry Garfield (larry@garfieldtech.com), Ilija Tovilo (tovilo.ilija@gmail.com)
Date
2020-10-04
Version
0.9
Source
wiki.php.net/rfc/adts

Discussions on the mailing list

[RFC] Enumerations
by Larry Garfield · 54 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:53 UTC

Introduction

This is an over-arching description of a multi-step process to add Algebraic Data Types to PHP. That effort is happening over multiple implementation RFCs in order to keep them individually digestible. Algebraic Data Types are a valuable tool in data modeling, and in “making invalid states unrepresentable,” an effective technique for avoiding many classes of bug.

Proposal

This proposal is implemented in stages. Each stage has its own RFC. Consult the list below for details of each. They are listed in approximately the order in which they can and should be implemented, although in some cases the order may be safely reversed.

  • Enumerations - The basic unit enumeration type.
  • Tagged Unions - Associating values with enum cases to create tagged unions.
  • Pattern Matching ''is'' keyword - Pattern matching for objects, enumerations, and similar structures. Mainly to condense conditional logic around the structure of enumerations and value objects.
  • isIdentical() method override (future scope)
  • Advanced pattern matching (future scope)