3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

preferences:
25.38 ms | 404 KiB | 5 Q