3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] class HookWithDependency { public function __construct( public readonly ?string $name = NULL, public readonly ?string $type = NULL, ) { } } #[HookWithDependency(name: 'bar')] class Example {} $reflectionClass = new \ReflectionClass(Example::class); var_dump($reflectionClass->getAttributes()[0]->newInstance());
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
object(HookWithDependency)#3 (2) { ["name"]=> string(3) "bar" ["type"]=> NULL }

preferences:
62.07 ms | 406 KiB | 5 Q