enum_exists
(PHP 8 >= 8.1.0)
enum_exists — 检测是否定义对应的枚举
说明
enum_exists(string
$class
, bool $autoload
= true
): bool本函数检测是否定义指定的枚举。
返回值
如果 enum
已定义,返回 true
,否则就返回 false
。
范例
示例 #1 enum_exists() 例子
<?php
// 在使用之前检测枚举是否存在
if (enum_exists(Suit::class)) {
$myclass = Suit::Hearts;
}
?>
参见
- function_exists() - 如果给定的函数已经被定义就返回 true
- class_exists() - 检查类是否已定义
- interface_exists() - 检查接口是否已被定义
- get_declared_classes() - 返回由已定义类的名字所组成的数组

User Contributed Notes
There are no user contributed notes for this page.