php8.5
Home/ Manual/ reflection / reflectionattribute/ ReflectionAttribute::newInstance

ReflectionAttribute::newInstance

PHP function Edit on GitHub ✎

(PHP 8)

Instantiates the attribute class represented by this ReflectionAttribute class and arguments

Description

ReflectionAttribute::newInstance(): object

Instantiates the attribute class represented by this ReflectionAttribute class and arguments.

Parameters Parameters

Return Values

New instance of the attribute.

Errors/Exceptions

Throws an Error if the attribute is applied to a target it cannot be used on. For internal attributes, this happens here instead of at compile time when the declaration uses #[\DelayedTargetValidation].

Changelog

VersionDescription
8.5.0Now throws an Error for an internal attribute applied to an invalid target when the target validation was delayed with #[\DelayedTargetValidation].

Source: reference/reflection/reflectionattribute/newinstance.xml · from the official PHP manual (php/doc-en)