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.
Slide Deck Link: https://bit.ly/37AGwtD
docker build -t enums-example docker/examples/.
docker run --rm -it -v $PWD:/app enums-example gcc -o bin/enum src/example_enum.c
docker run --rm -it -v $PWD:/app enums-example ./bin/enum
docker run --rm -it -v $PWD:/app enums-example hhvm src/example_enum.hh
docker run --rm -it -v $PWD:/app enums-example python3 src/example_enum.py
docker run --rm -it -v $PWD:/app enums-example composer install
docker run --rm -it -v $PWD:/app enums-example vendor/bin/phpunit tests
- See
src/
for code examples, including PHP, C, Hack, and Python - Dockerfile for Code Examples
- Dockerfile for SplEnum