(PHP 8)
ReflectionAttribute::getTarget — Returns the target on which the attribute is declared
Returns the kind of declaration to which this attribute is applied. This is distinct from the set of targets permitted by the attribute class.
Bu işlevin bağımsız değişkeni yoktur.
Returns the corresponding
Attribute::TARGET_* constant.
The permitted targets of the attribute class can instead be obtained from
the flags property of its Attribute
instance.
Örnek 1 Distinguishing actual and permitted attribute targets
<?php
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)]
class Marker {}
#[Marker]
class Example
{
#[Marker]
public $value;
}
$class = new ReflectionClass(Example::class);
$property = new ReflectionProperty(Example::class, 'value');
var_dump($class->getAttributes(Marker::class)[0]->getTarget());
var_dump($property->getAttributes(Marker::class)[0]->getTarget());
$definition = new ReflectionClass(Marker::class);
var_dump($definition->getAttributes(Attribute::class)[0]->newInstance()->flags);
?>Yukarıdaki örneğin çıktısı:
int(1) int(8) int(9)