1. How Would You Create Enums in PHP
Updated on: 2019-09-24
Posted on: 2019-09-24
Enums, or enumerations, are types of values that can be assigned to a variable with a limited number of possible values.
Until today PHP does not have a native enum type. It offers a very basic implementation using SPL extension, but I prefer to believe that implementation is not ideal.
Alternatively, the Div PHP Enum package provides is a solution for this using classes. Thanks to some interesting features of PHP, you can make a taxonomy (hierarchy of terms) and give behavior to each term similar to what we can achieve using the Java language.
Read read article to learn how you can implement PHP enums using pure PHP code, thus without additional extensions.
More ... Post a comment See comments (0) Trackbacks (0)
Until today PHP does not have a native enum type. It offers a very basic implementation using SPL extension, but I prefer to believe that implementation is not ideal.
Alternatively, the Div PHP Enum package provides is a solution for this using classes. Thanks to some interesting features of PHP, you can make a taxonomy (hierarchy of terms) and give behavior to each term similar to what we can achieve using the Java language.
Read read article to learn how you can implement PHP enums using pure PHP code, thus without additional extensions.
More ... Post a comment See comments (0) Trackbacks (0)