CakeFest 2024: The Official CakePHP Conference

enum_exists

(PHP 8 >= 8.1.0)

enum_exists列挙型が定義されているかを調べる

説明

enum_exists(string $enum, bool $autoload = true): bool

この関数は、指定された 列挙型 が定義されているかを調べます。

パラメータ

enum

列挙型の名前。この名前は、大文字小文字を区別せずに比較されます。

autoload

まだロードされていない場合に オートロード するかどうか。

戻り値

enum が定義済みの列挙型である場合、 true を返します。そうでない場合、false を返します。

例1 enum_exists() の例

<?php
// Check that the enum exists before trying to use it
if (enum_exists(Suit::class)) {
$myclass = Suit::Hearts;
}
?>

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top