ReflectionClass::hasConstant
(PHP 5 >= 5.1.0)
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() - プロパティが定義されているかどうかを調べる