What is the difference between classes vs enums in PHP 8.1?
One of the common questions that I have been asked is what is the difference between classes and enums. Class(es) and enum(s) share many similarities but differ in some aspects. The following are some of the differences between Class and Enum:
Classes | Enums | |
Syntax |
|
|
Properties | ✔ | ✘ |
Static Properties | ✔ | ✘ |
Methods | ✔ | ✔ |
Static Methods | ✔ | ✔ |
Instantiating: | ✔ | ✘ |
Implement interfaces | ✔ | ✔ |
Inheritance: | ✔ | ✘ |
Magic Constants | ✔ | ✔ |
Traits | ✔ | ✔ (without properties) |
Please login or create new account to add your comment.