- Output for 8.1.0 - 8.1.30, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1
- bool(true) bool(true)
<?php
#[\Attribute]
final class Attr
{
public function __construct(
public string $string,
public int $int,
) {}
}
final class A
{
public function __construct(
#[Attr(string: 'a', int: 1)]
public string $a
) {}
}
$reflection = new \ReflectionClass(A::class);
var_dump($reflection->getConstructor()->getParameters()[0]->getAttributes()[0]->getTarget() === \Attribute::TARGET_PARAMETER);
var_dump($reflection->getProperty('a')->getAttributes()[0]->getTarget() === \Attribute::TARGET_PROPERTY);