(PHP 8 >= 8.1.0)
enum_exists — Checks if the enum has been defined
$enum
, bool $autoload
= true
): boolThis function checks whether or not the given enum has been defined.
enum
The enum name. The name is matched in a case-insensitive manner.
autoload
Whether to call __autoload by default.
Returns true
if enum
is a defined enum,
false
otherwise.
Example #1 enum_exists() example
<?php
// Check that the enum exists before trying to use it
if (enum_exists(Suit::class)) {
$myclass = Suit::Hearts;
}
?>