spatie/enum

Switch operator usage

GSpecDrum opened this issue · 2 comments

Hello! Thanks for this library!

I have a question:
May I use this enums in switch operators? Have usage of this library with switch operator some pitfalls?

Hey,

yes you can use the enums in a switch statement like follows:

switch(Gender::MALE()) {
  case Gender::FEMALE():
    return 'female';
  case Gender::MALE():
    return 'male';
}

That's just a super stupid example but tested in a project and it perfectly works. 🙂

Thanks for fast and clear answer!