Enums helpers
List of functions that works for PHP enums.
is_enum
Check if object or class is a PHP enum.
enum_is_backed
Check if object or class is a backed PHP enum.
has_case
Check if object or class is a PHP enum that has the specified case.
get_enum_class
Get class string from enum object.
enum_to_array
Converts PHP enum object or class into an array. In case of a backed enum it will add its values.
enum_values
Gets array of values from PHP backed enum.
GetsAttributes
This is not a function but still serves as a utility. Make sure you only use this with backed enums.
This trait will add some functions to the PHP enums so they can be converted to arrays to be used in multiple contexts (like HTML selects, etc).
Description
This is a PHP attribute to be used in those enum cases to be used along with GetsAttribute
trait:
More details of their usage below.
asSelectArray
The only public method available on this trait which will get all described cases of your enum.
Now imagine the case having the enum shown before:
Last updated