Library PHP Tek 2024 Embracing Enums
Embracing Enums

Embracing Enums

AS
Andy Snell
PHP Tek 2024 Intermediate (some prior knowledge necessary) Standard (50 minutes)

In January 2020, I delivered a conference talk titled "Enums: The Missing Data Type", which ended on a sour note: PHP probably would not have a native type for handling enumerations any time soon. To my surprise and delight, PHP 8.1 would release with a new "Enum" type less than two years later. Now we can really explore enumerations: both the theory behind them and the current PHP implementation. We’ll cover how representing things like statuses with enums improves immutability, readability, and type safety; the different types of enums available to us; and address the most common questions: - Why can't PHP enums be extended like other classes? - Why can't backed PHP enums be cast to a string or int? - Why can't backed PHP enums be used as an array key?