3v4l.org

run code in 500+ PHP versions simultaneously
<?php #[Attribute] class Attr { public function __construct(public int $i) {} } #[Attr(i: 1)] #[NonExistentAttr(somevalue: 'string')] class C {} $refl = new ReflectionClass('C'); $attrs = $refl->getAttributes(); print_r($attrs); print_r($attrs[0]->newInstance()); print_r($attrs[1]->newInstance());
Output for 8.4.9 - 8.4.26, 8.5.0 - 8.5.11
Array ( [0] => ReflectionAttribute Object ( [name] => Attr ) [1] => ReflectionAttribute Object ( [name] => NonExistentAttr ) ) Attr Object ( [i] => 1 ) Fatal error: Uncaught Error: Attribute class "NonExistentAttr" not found in /in/5pAHA:16 Stack trace: #0 /in/5pAHA(16): ReflectionAttribute->newInstance() #1 {main} thrown in /in/5pAHA on line 16
Process exited with code 255.
Output for 8.2.32 - 8.2.34, 8.3.0 - 8.3.35
Array ( [0] => ReflectionAttribute Object ( ) [1] => ReflectionAttribute Object ( ) ) Attr Object ( [i] => 1 ) Fatal error: Uncaught Error: Attribute class "NonExistentAttr" not found in /in/5pAHA:16 Stack trace: #0 /in/5pAHA(16): ReflectionAttribute->newInstance() #1 {main} thrown in /in/5pAHA on line 16
Process exited with code 255.

preferences:
30.57 ms | 1140 KiB | 9 Q