DEV Community

Sam Newby
Sam Newby

Posted on

Enums in PHP8.1

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!

Top comments (1)

drbyte profile image
Chris Brown

Yes! Yay!

This article goes into more detail on the topic: