Talk in English - US at php[world] 2019
Checkout the code: https://github.com/andysnell/enums-phps-missing-data-type
View Slides: https://slides.com/andysnell/php-world-enums
Short URL: https://joind.in/talk/e65d5 (QR-Code (opens in new window))
PHP may not have a native data type for an enumerated type (“enum”), like other programming languages, but there are userland solutions we can leverage to get access to this powerful data type. We’ll see how representing things like statuses with enums provides immutability, improved readability, and type safety — preventing the kind of errors that happen with “magic strings” and class constants. In this Talk, we’ll be making our own immutable enums from scratch in order to explore the concept, but we’ll also introduce two libraries for use in your production code. We’ll also demystify the imposing-sounding “finite state machine” by using using immutable enum objects to regulate the transitions between statuses.