-1

There is a lot of type checking functions in PHP (is_string, is_resource etc) but there is no function to check if variable is an Enum or a Case. How to check it properly?

Grzegorz Adam Kowalski
  • 5,243
  • 3
  • 29
  • 40

1 Answers1

1

You can check that it implements the UnitEnum interface.

if ($variable instanceof UnitEnum) echo "it's an enum.";

According to the PHP manual, this interface exists specifically for type checking.

Don't Panic
  • 41,125
  • 10
  • 61
  • 80