(PHP 7 >= 7.1.0, PHP 8)
ReflectionClassConstant 類別會回報類別常數的相關資訊。
$class
, 字串 (string) $name
, 布林 (bool) $return
= ?): 字串 (string)類別常數的名稱。唯讀,嘗試寫入時會拋出 ReflectionException。
定義類別常數的類別名稱。唯讀,嘗試寫入時會拋出 ReflectionException。
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() 已移除。 |