3v4l.org

run code in 500+ PHP versions simultaneously
<?php #[\Attribute(\Attribute::TARGET_CLASS)] class TestAttribute { public function __construct( public readonly mixed $first, public readonly mixed $second, ) {} } #[TestAttribute(first: 1, second: 2, third: 3)] class TargetClass {} $reflection = new \ReflectionClass(TargetClass::class); $attributes = $reflection->getAttributes(); $instance = $attributes[0]->newInstance(); print_r($instance);
Output for 8.2.31 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
Fatal error: Uncaught Error: Unknown named parameter $third in /in/p2IWT:13 Stack trace: #0 /in/p2IWT(18): ReflectionAttribute->newInstance() #1 {main} thrown in /in/p2IWT on line 13
Process exited with code 255.

preferences:
29.03 ms | 1152 KiB | 7 Q