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);
Output for 8.1.0 - 8.1.31, 8.2.0 - 8.2.27, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
bool(true) bool(true)

preferences:
55.58 ms | 406 KiB | 5 Q