(PHP 8 >= 8.1.0)
enum_exists — Checks if the enum has been defined
enum_exists(string $enum, bool $autoload = true): bool
This function checks whether or not the given enum has been defined.
enumThe enum name. The name is matched in a case-insensitive manner.
autoloadWhether to autoload if not already loaded.
Example #1 enum_exists() example
<?php
// Check that the enum exists before trying to use it
if (enum_exists(Suit::class)) {
$myclass = Suit::Hearts;
}
?>
© 1997–2025 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/function.enum-exists.php