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; why limitations like not being able to extend enums are actually a good thing; and some tricks to get the most out of using enums in your code.

Comments

Please login to leave a comment