Library PHP Tek 2024 Embracing Enums
Embracing Enums

Log in to watch this talk

You need to be logged in to access this video. If you don't have an account, purchase a virtual pass for the latest php[tek] conference to get access to the full video library.

Embracing Enums

Andy Snell 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?