enum_exists()
enum_exists() — Checks if the enum has been defined.
Built-in function of PHP 8.5. The manual lists it as available in PHP 8 >= 8.1.0. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
This function checks whether or not the given enum has been defined.
Signature
enum_exists(string $enum, bool $autoload = true): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $enum | string | The enum name. The name is matched in a case-insensitive manner. |
| $autoload | bool | Whether to autoload if not already loaded. |
Return value
Returns true if enum is a defined enum, false otherwise.
Example
A runnable snippet:
// Check that the enum exists before trying to use it if (enum_exists(Suit::class)) { $myclass = Suit::Hearts; }
See also
function_exists(), class_exists(), interface_exists(), get_declared_classes()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page enum_exists() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.