phpday 2027 - Call for Papers

The ReflectionAttribute class

(PHP 8)

Вступ

The ReflectionAttribute class provides information about an Attribute.

Короткий огляд класу

class ReflectionAttribute implements Reflector {
/* Константи */
public const int IS_INSTANCEOF;
/* Властивості */
public string $name;
/* Методи */
private function __construct()
public function getArguments(): array
public function getName(): string
public function getTarget(): int
public function isRepeated(): bool
public function newInstance(): object
}

Властивості

name

The name of the attribute.

Попередньо визначені константи

ReflectionAttribute Flags

ReflectionAttribute::IS_INSTANCEOF int

Retrieve attributes using an instanceof check. Used as the flags argument of ReflectionClass::getAttributes() and the equivalent methods of the other reflection classes. When set, the name argument matches attributes whose class is the given class or a subclass of it, or implements the given interface, instead of only matching the exact class name.

Зауваження:

When ReflectionAttribute::IS_INSTANCEOF is used, the class name specified by name is autoloaded before any attribute is examined. If it cannot be loaded, the error or exception thrown while loading it is propagated. If the class does not exist, an Error is thrown.

PHP also autoloads the class of every attribute declared on the element being reflected, including attributes that do not match the filter, because it uses instanceof to filter them. An attribute whose class does not exist is ignored. If an error or exception is thrown while loading an attribute class, for example because a parent class is missing or its file contains a syntax error, it is propagated, even if the attribute does not match the filter.

Зауваження:

The values of these constants may change between PHP versions. It is recommended to always use the constants and not rely on the values directly.

Журнал змін

Версія Опис
8.4.0 All class constants are now typed.
8.4.0 Added ReflectionAttribute::$name.

Зміст

+add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top