(PHP 5 >= 5.1.2, PHP 7, PHP 8)
ReflectionClass::hasConstant — 檢查是否定義了常數
name
要檢查的常數名稱。
範例 #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)