PHP Conference Japan 2024

ReflectionType 類別

(PHP 7, PHP 8)

簡介

ReflectionType 類別會回報函式參數/回傳類型或類別屬性類型的相關資訊。 Reflection 擴充套件宣告下列子類型:

類別概要

abstract class ReflectionType implements Stringable {
/* 方法 */
公開 allowsNull(): 布林值
公開 __toString(): 字串
}

更新日誌

版本 說明
8.0.0 ReflectionType 已成為抽象類別,且 ReflectionType::isBuiltin() 已移至 ReflectionNamedType::isBuiltin()

目錄

新增註記

使用者貢獻的註記 4 則註記

1franck
4 年前
對於那些遇到 ReflectionType::__toString() 已被棄用的通知的人,請改用尚未記錄的方法 ReflectionType::getName()。
Ondej Mirtes
4 年前
ReflectionType::getName() 方法不存在。這在過去可能虛擬地存在,但現在已經不存在了。它存在於 ReflectionNamedType 中,它曾經是 ReflectionType 的唯一子類別。所以你本來可以依賴它。

但在 PHP 8 中,還有 ReflectionUnionType,它沒有 getName() 方法。因此,為了支援 PHP 8,您需要同時支援 ReflectionNamedType 和 ReflectionUnionType。
benjamin dot morel at gmail dot com
4 年前
已知的子類別

- ReflectionNamedType
- ReflectionUnionType
roland at mxchange dot org
4 年前
我猜是 <?php ReflectionNamedType::getName(); ?>
To Top