3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[Attribute(Attribute::TARGET_FUNCTION)] class Test {} class Foo { #[Test] public int $test; } echo "Creating foo: "; $f = new Foo(); echo "done\n"; echo "Performing reflection: "; $foo = new ReflectionClass($f); $test = $foo->getProperty('test'); $attributes = $test->getAttributes(); echo "done\n"; echo "instantiating attribute ["; foreach ($attributes as $attribute) { echo $attribute->getName() . ']: '; $attribute->newInstance(); } echo "\n";
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
Creating foo: done Performing reflection: done instantiating attribute [Test]: Fatal error: Uncaught Error: Attribute "Test" cannot target property (allowed targets: function) in /in/UqQKi:24 Stack trace: #0 /in/UqQKi(24): ReflectionAttribute->newInstance() #1 {main} thrown in /in/UqQKi on line 24
Process exited with code 255.

preferences:
67.12 ms | 406 KiB | 5 Q