PHPKonf 2020 Online

The ReflectionType class

(PHP 7)

简介

ReflectionType 类用于获取函数、类方法的参数或者返回值的类型。

类摘要

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

Table of Contents

add a note add a note

User Contributed Notes 4 notes

up
25
1franck
10 months ago
For those who stumble on notice about ReflectionType::__toString() beeing deprecated, use method ReflectionType::getName() instead which is not yet documented.
up
2
roland at mxchange dot org
8 months ago
I guess it is <?php ReflectionNamedType::getName(); ?> ?
up
1
Ondej Mirtes
2 months 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
0
benjamin dot morel at gmail dot com
2 months ago
Known subclasses:

- ReflectionNamedType
- ReflectionUnionType
To Top