CakeFest 2024: The Official CakePHP Conference

ReflectionClass::hasConstant

(PHP 5 >= 5.1.2, PHP 7, PHP 8)

ReflectionClass::hasConstant定数が定義されているかどうかを調べる

説明

public ReflectionClass::hasConstant(string $name): bool

そのクラスで特定の定数が定義されているかどうかを調べます。

パラメータ

name

調べたい定数の名前。

戻り値

定数が定義されている場合に true、それ以外の場合に false を返します。

例1 ReflectionClass::hasConstant() の例

<?php
class Foo {
const
c1 = 1;
}

$class = new ReflectionClass("Foo");

var_dump($class->hasConstant("c1"));
var_dump($class->hasConstant("c2"));
?>

上の例の出力は、 たとえば以下のようになります。

bool(true)
bool(false)

参考

add a note

User Contributed Notes

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