Implementing Enumerations (Enum) in PHP: How to Do It Right?
Hello everyone! I'm a beginner in PHP (writing for about a year) and I've run into a problem. In the project, I need to store order statuses: "new", "processing", "shipped", "delivered". Currently, I'm using regular constants:
```php
define('STATUS_NEW', 1);
define('STATUS_PROCESSING', 2);
define('STATUS_SHIPPED', 3);
define('STATUS_DELIVERED', 4);
```
But this is inconvenient: first, I can accidentally pass any number instead of a status to a function, and PHP won't throw an error. Second, if I need to add a description or method for a status (for example, "can the order be canceled?"), I have to write separate functions. Third, when displaying a list of statuses in a form dropdown, I get confused with keys and values.
I've heard that native enums appeared in PHP 8.1, but the project runs on PHP 7.4, and I can't upgrade yet.