略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ReflectionType

2024-11-15

ReflectionType 类

(PHP 7, PHP 8)

简介

ReflectionType 类用于获取函数、类方法的参数或者返回值的类型。 反射扩展声明了以下子类型:

类摘要

abstract class ReflectionType {
/* 方法 */
public allowsNull(): bool
public __toString(): string
}

更新日志

版本 说明
8.0.0 ReflectionType 修改为了抽象类,并且 ReflectionType::isBuiltin() 被移动到了 ReflectionNamedType::isBuiltin()

目录

add a noteadd a note

User Contributed Notes 4 notes

up
33
1franck
2 years ago
For those who stumble on notice about ReflectionType::__toString() beeing deprecated, use method ReflectionType::getName() instead which is not yet documented.
up
12
Ondej Mirtes
1 year ago
Method ReflectionType::getName() does not exist. This may have been virtually true in the past but not anymore. It exists on ReflectionNamedType which used to be the only child class of ReflectionType. So you could have kind of relied on that.

But in PHP 8 there's also ReflectionUnionType which doesn't have the getName() method. So in order to support PHP 8, you need to support both ReflectionNamedType and ReflectionUnionType.
up
2
roland at mxchange dot org
2 years ago
I guess it is <?php ReflectionNamedType::getName(); ?> ?
up
2
benjamin dot morel at gmail dot com
1 year ago
Known subclasses:

- ReflectionNamedType
- ReflectionUnionType

官方地址:https://www.php.net/manual/en/class.reflectiontype.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3