Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

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 modeExit fullscreen mode

And then in a class that uses theCase 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)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
drbyte profile image
Chris Brown
  • Joined

Yes! Yay!

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

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Building the modern affordable cloud at vizalo.co
  • Location
    London
  • Education
    University of Hertfordshire
  • Work
    Founder of @vizalo
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp