ReflectionEnum::hasCase
(PHP 8 >= 8.1.0)
ReflectionEnum::hasCase — 在枚举上检测条目
说明
public ReflectionEnum::hasCase(string
$name
): bool检测在枚举是是否定义指定的条目。
参数
-
name
-
要检测的条目。
返回值
条目已定义时返回 true
,没有时返回 false
。
范例
示例 #1 ReflectionEnum::hasCase() 例子
<?php
enum Suit
{
case Hearts;
case Diamonds;
case Clubs;
case Spades;
}
$rEnum = new ReflectionEnum(Suit::class);
var_dump($rEnum->hasCase('Hearts'));
var_dump($rEnum->hasCase('Horseshoes'));
?>
以上例程会输出:
bool(true) bool(false)
add a note
User Contributed Notes
There are no user contributed notes for this page.
备份地址:http://www.lvesu.com/blog/php/reflectionenum.hascase.php