PHP 8.0.24 Released!

enum_exists

(PHP 8 >= 8.1.0)

enum_existsChecks if the enum has been defined

Descripción

enum_exists(string $enum, bool $autoload = true): bool

This function checks whether or not the given enum has been defined.

Parámetros

enum

The enum name. The name is matched in a case-insensitive manner.

autoload

Whether to call __autoload by default.

Valores devueltos

Returns true if enum is a defined enum, false otherwise.

Ejemplos

Ejemplo #1 enum_exists() example

<?php
// Check that the enum exists before trying to use it
if (enum_exists(Suit::class)) {
    
$myclass Suit::Hearts;
}
?>

Ver también

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top