3 ms·
Internally, Enums inherit a lot from classes. I wrote an indepth article about this: https://php.watch/versions/8.1/enums#enum-exists https://php.watch/version
by Ayesh 5y ago
Internally, Enums inherit a lot from classes.
I wrote an indepth article about this: https://php.watch/versions/8.1/enums#enum-exists https://php.watch/versions/8.1/enums#enum-exists
There is an `enum_exists` function that only returns true for Enums. It's fairly unintuitive to combine class_exists with enum_exists to filter out Enums, I agree.
- donatj 5y agoIsn’t that the same behavior/pattern for traits though? At least it’s consistent.
- pdenton 5y agoThat was easy to test, and no. class_exists returns false for traits and they can't be used as parameter types. It throws a TypeError when I do that (even though the instance I pass uses the trait).