3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[Attribute] class y { function foo() { return __METHOD__; } } #[X, Y] function f() { } $ref = new \ReflectionFunction('\f'); try { if ($ref->getAttributes()[0]->getName() === 'X') { print 'Look mom! No hands' . PHP_EOL; } if ($ref->getAttributes()[1]->getName() === 'Y') { print $ref->getAttributes()[1]->newInstance()->foo(); } } catch (\Error $e) { # other errors var_dump($e->getMessage()); } ?>
Output for 8.1.32 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Look mom! No hands y::foo

preferences:
50.11 ms | 851 KiB | 4 Q