ReflectionEnum::getBackingType
(PHP 8 >= 8.1.0)
ReflectionEnum::getBackingType — 获取枚举回退的类型
说明
如果一个枚举是回退枚举,该方法会根据枚举回退的类型,
返回 ReflectionType 的实例。
如果不是个回退枚举,会返回 null
。
参数
此函数没有参数。
返回值
ReflectionType 的实例。
如果 Enum 没有回退的类型时,返回 null
。
范例
示例 #1 ReflectionEnum::getBackingType() 例子
<?php
enum Suit: string
{
case Hearts = 'H';
case Diamonds = 'D';
case Clubs = 'C';
case Spades = 'S';
}
$rEnum = new ReflectionEnum(Suit::class);
$rBackingType = $rEnum->getBackingType();
var_dump((string)$rBackingType);
?>
以上例程会输出:
string(6) "string"

User Contributed Notes
There are no user contributed notes for this page.
备份地址:http://www.lvesu.com/blog/php/reflectionenum.getbackingtype.php