略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ReflectionEnum::getCase

2024-04-27

ReflectionEnum::getCase

(PHP 8 >= 8.1.0)

ReflectionEnum::getCase返回指定的枚举条目

说明

public ReflectionEnum::getCase(string $name): ReflectionEnumUnitCase

根据名称返回指定枚举条目的反射对象。 如果请求的条目未定义,将抛出 ReflectionException

参数

name

要获取的条目名称。

返回值

ReflectionEnumUnitCaseReflectionEnumBackedCase 的实例,具体视情况而定。

范例

示例 #1 ReflectionEnum::getCase() 例子

<?php
enum Suit
{
    case 
Hearts;
    case 
Diamonds;
    case 
Clubs;
    case 
Spades;
}

$rEnum = new ReflectionEnum(Suit::class);

$rCase $rEnum->getCase('Clubs');

var_dump($rCase->getValue());
?>

以上例程会输出:

enum(Suit::Clubs)

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/reflectionenum.getcase.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3