3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[\Attribute(\Attribute::TARGET_PARAMETER)] class Inject { public function __construct( public readonly string $id ) { } } class MyFoo { public function __construct( #[Inject('baz-value')] public readonly int $bar, ){} } $ref = new ReflectionClass(MyFoo::class); echo "Checking Parameters : "; $parameters = $ref->getConstructor()->getParameters(); foreach ($parameters as $parameter) { foreach ($parameter->getAttributes() as $attribute) { $attribute->newInstance(); } } echo "✅\n\n"; echo "Checking Properties : "; $properties = $ref->getProperties(); foreach ($properties as $property) { foreach ($property->getAttributes() as $attribute) { $attribute->newInstance(); } } echo "✅\n\n";
Output for git.master_jit, git.master
Checking Parameters : ✅ Checking Properties : Fatal error: Uncaught Error: Attribute "Inject" cannot target property (allowed targets: parameter) in /in/rMqqA:30 Stack trace: #0 /in/rMqqA(30): ReflectionAttribute->newInstance() #1 {main} thrown in /in/rMqqA on line 30
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
40.9 ms | 405 KiB | 5 Q