3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); namespace X; #[\Attribute] class MyAttr { public function __construct(private string $n) {} } #[\AllowDynamicProperties] #[MyAttr('foo')] class Cl { } print_r(array_map(function (\ReflectionAttribute $v) { return class_exists($v->getName(), false) ? $v->newInstance() : $v; }, (new \ReflectionClass(Cl::class))->getAttributes()));
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Array ( [0] => AllowDynamicProperties Object ( ) [1] => X\MyAttr Object ( [n:X\MyAttr:private] => foo ) )
Output for 8.1.0 - 8.1.33
Array ( [0] => ReflectionAttribute Object ( ) [1] => X\MyAttr Object ( [n:X\MyAttr:private] => foo ) )

preferences:
71.14 ms | 407 KiB | 5 Q