enum_exists

(PHP 8 >= 8.1.0)

enum_existsChecks if the enum has been defined

说明

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

This 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;
}
?>

参见

User Contributed Notes

There are no user contributed notes for this page.
PHP8中文手册 站长在线 整理 版权归PHP文档组所有