ReflectionClassConstant::isEnumCase
(PHP 8 >= 8.1.0)
ReflectionClassConstant::isEnumCase — クラス定数が、列挙型の case かどうかを調べる
パラメータ
この関数にはパラメータはありません。
例
例1 ReflectionClassConstant::isEnumCase() の例
通常のクラス定数と、列挙型の case を区別する例です。
<?php
enum Status
{
const BORING_CONSTANT = 'test';
const ENUM_VALUE = Status::PUBLISHED;
case DRAFT;
case PUBLISHED;
case ARCHIVED;
}
$reflection = new ReflectionEnum(Status::class);
foreach ($reflection->getReflectionConstants() as $constant) {
echo "{$constant->name} is ",
$constant->isEnumCase() ? "an enum case" : "a regular class constant",
PHP_EOL;
}
?>
上の例の出力は以下となります。
BORING_CONSTANT is a regular class constant ENUM_VALUE is a regular class constant DRAFT is an enum case PUBLISHED is an enum case ARCHIVED is an enum case
+add a note
User Contributed Notes
There are no user contributed notes for this page.
↑ and ↓ to navigate •
Enter to select •
Esc to close
Press Enter without
selection to search using Google