PHPerKaigi 2021

Класс ReflectionType

(PHP 7)

Введение

Класс ReflectionType сообщает информацию о типе возвращаемого значения функции.

Обзор классов

abstract ReflectionType {
/* Методы */
public allowsNull ( ) : bool
public __toString ( ) : string
}

Список изменений

Версия Описание
8.0.0 ReflectionType стал абстрактным, а метод ReflectionType::isBuiltin() был перемещён в ReflectionNamedType::isBuiltin().

Содержание

add a note add a note

User Contributed Notes 4 notes

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

- ReflectionNamedType
- ReflectionUnionType
To Top