DEV Community

Sam Newby
Sam Newby

Posted on

2

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!

Retry later

Top comments (1)

Collapse
 
drbyte profile image
Chris Brown

Yes! Yay!

This article goes into more detail on the topic: stitcher.io/blog/php-enums

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Retry later