Php/docs/reflectionclass.hasconstant

提供:Dev Guides
< Php
移動先:案内検索

ReflectionClass::hasConstant

(PHP 5 >= 5.1.2, PHP 7)

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


説明

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

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


パラメータ

name
調べたい定数の名前。


返り値

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


例1 ReflectionClass::hasConstant() の例

<?phpclass Foo {    const c1 = 1;}$class = new ReflectionClass("Foo");var_dump($class->hasConstant("c1"));var_dump($class->hasConstant("c2"));?>

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


bool(true)
bool(false)

参考