3v4l.org

run code in 500+ PHP versions simultaneously
<?php class RandomValue { public string $value; public function __construct(string $prefix) { $this->value = $prefix . random_int(1,100); } } #[Attribute] class Foo { public function __construct(public readonly RandomValue $bar) {} } #[Foo(new RandomValue('FooBar: '))] class Bar { } $ref = new ReflectionClass(Bar::class); $attribute = $ref->getAttributes()[0]; var_dump($attribute->getArguments()); var_dump($attribute->getArguments()); var_dump($attribute->getArguments());

preferences:
22.01 ms | 484 KiB | 6 Q