ReflectionClass::hasConstant

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

説明

public bool ReflectionClass::hasConstant(string $name)

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

パラメータ

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)

参考

  • ReflectionClass::hasMethod
  • ReflectionClass::hasProperty