PHP Conference Japan 2024

ReflectionClassConstant 類別

(PHP 7 >= 7.1.0, PHP 8)

簡介

ReflectionClassConstant 類別會回報類別常數的相關資訊。

類別概要

class ReflectionClassConstant implements Reflector {
/* 常數 */
public const int IS_PUBLIC;
公開 (public) 常數 (const) 整數 (int) IS_PROTECTED;
公開 (public) 常數 (const) 整數 (int) IS_PRIVATE;
公開 (public) 常數 (const) 整數 (int) IS_FINAL;
/* 屬性 (Properties) */
公開 (public) 字串 (string) $name;
公開 (public) 字串 (string) $class;
/* 方法 (Methods) */
公開 (public) __construct(物件 (object) | 字串 (string) $class, 字串 (string) $constant)
公開 (public) 靜態 (static) export(混合 (mixed) $class, 字串 (string) $name, 布林 (bool) $return = ?): 字串 (string)
公開 (public) getAttributes(空值 (null) | 字串 (string) $name = null, 整數 (int) $flags = 0): 陣列 (array)
公開 (public) getDocComment(): 字串 (string) | 假 (false)
公開 (public) getModifiers(): 整數 (int)
公開 (public) getName(): 字串 (string)
公開 getValue(): 混合
公開 hasType(): 布林值
公開 isFinal(): 布林值
公開 __toString(): 字串
}

屬性

name

類別常數的名稱。唯讀,嘗試寫入時會拋出 ReflectionException

class

定義類別常數的類別名稱。唯讀,嘗試寫入時會拋出 ReflectionException

預定義常數

ReflectionClassConstant 修飾符

ReflectionClassConstant::IS_PUBLIC 整數

表示 公開 常數。在 PHP 7.4.0 之前,值為 256

ReflectionClassConstant::IS_PROTECTED 整數

表示 保護 常數。在 PHP 7.4.0 之前,值為 512

ReflectionClassConstant::IS_PRIVATE 整數

表示 私有 常數。在 PHP 7.4.0 之前,值為 1024

ReflectionClassConstant::IS_FINAL 整數

表示 final 常數。從 PHP 8.1.0 開始可用。

注意事項:

這些常數的值可能會在不同 PHP 版本之間有所變更。建議始終使用常數,而不要直接依賴值。

更新日誌

版本 說明
8.4.0 8.0.0 類別常數現在已設定類型。
8.0.0 8.0.0 ReflectionClassConstant::export() 已移除。

目錄

新增註釋

使用者貢獻的註釋

此頁面沒有使用者貢獻的註釋。
To Top