PHP may not have a native data type for an Enumerated Type like other programming languages, but there are other solutions we can leverage to represent a member of a set of values. 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 session, we’ll be making our own immutable enums from scratch in order to explore the concept, but we’ll also introduce some open source 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 member elements.

Comments

Comments are closed.

Dana Luther at 12:09 on 26 Jan 2020

This was a great explanation of what the benefits of a true enum type would be. I appreciated the examples of the evolution of the code. Additionally, the slides were incredibly crisp and easily read from a distance.

What is it with Americans and giving talks at conferences? They are very good at engaging an audience and getting their points accross. Together with Cal Evans and Larry Garfield (to name a few), Andy Snell is also adept at speaking about technical stuff, which is not always evident.

Andy manages to give clear examples and solutions to common problems which all of us can relate to.

On the subject itself : it is certainly something I will delve deeper into, so thank you for pointing us in that direction.

Steve Winter at 19:27 on 26 Jan 2020

A well structured session, with great code samples and a nice mix of theory and example... somehow I left feeling like the session didn't live up to expectations, but I can't explain why - maybe it was because I had expected something revolutionary, but left thinking 'this is just a value object with a few extra methods'.

Well structured talk, I liked it :)

Great talk on the enum data type.
Nice comparison on how the enum type is implemented in other languages and how it is used in userland solutions.