Dynamic Enum Cases¶
PHP offers the constant() function to reach the value of a constant, when knowing its name.
This also works for class constant, using the class::constant name. This is an alternative to the class::{$name} syntax, that was introduced in PHP 8.3.
And the constant() call also works on enumeration cases, which are, eventually, also class constants.
See Also¶
Dynamic Enum Cases [Try me]