Skip to content

Code Repo, Slide Links, and Resources for "Enums: The Missing Data Type"

Notifications You must be signed in to change notification settings

andysnell/enums-phps-missing-data-type

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enums: The Missing Data Type

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.

Latest Slides

Enums: The Missing Data Type Slide Deck Link: https://bit.ly/37AGwtD

Running Code Examples

Build Docker Image

docker build -t enums-example docker/examples/. 

Run C Example

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 

Run Hack Example

docker run --rm -it -v $PWD:/app enums-example hhvm src/example_enum.hh

Run Python Example

docker run --rm -it -v $PWD:/app enums-example python3 src/example_enum.py

Run PHP Tests

docker run --rm -it -v $PWD:/app enums-example composer install 
docker run --rm -it -v $PWD:/app enums-example vendor/bin/phpunit tests 

Additional Resources

  • See src/ for code examples, including PHP, C, Hack, and Python
  • Dockerfile for Code Examples
  • Dockerfile for SplEnum

Interesting Userland Package Implementations of Enum Objects

PHP RFCs and Internals Discussions

Other Resources

About

Code Repo, Slide Links, and Resources for "Enums: The Missing Data Type"

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages