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!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

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

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs