Enums in PHP8.1

Sam Newby - Feb 15 '21 - - Dev Community

At University I had used Java quite a bit and found Enums a great way to express data that I knew wasn't going to change and was super useful in many types of applications. However, when I got started with PHP and it didn't have Enums I was slightly surprised. However, that is going to change with PHP8.1 as Enums are coming to PHP!

To use Enums in our applications we will be able to do something like this:

enum Case {
  case Open;
  case Active;
  case Closed;
}
Enter fullscreen mode Exit fullscreen mode

And then in a class that uses the Case Enum we would be able to do something like this: $caseStatus = Case::Open;

I know for sure I will be using Enums in my applications when I can.

Hope you enjoyed, catch you later!

. . . . . . . . . . . .
Terabox Video Player