= 5.1.2, PHP 7, PHP 8)ReflectionClass::hasConstant — 檢查常量是否已經(jīng)定義說明public ReflectionClass::hasConstant(string $name)">

ReflectionClass::hasConstant

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

ReflectionClass::hasConstant檢查常量是否已經(jīng)定義

說明

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

檢查類中是否已經(jīng)定義了指定的常量。

參數(shù)

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)

參見