3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[Attribute(Attribute::TARGET_PROPERTY)] ## Look ma, I'm not targeting parameter with Attribute::TARGET_PARAMETER final class TargetTestPropertyAttribute { } final class TargetTest { public function __construct( #[TargetTestAttribute] public string $test ) { } } $ref = new ReflectionClass(TargetTest::class); $testAsProperty = $ref->getProperty('test'); $testAsParemter = $ref->getConstructor()->getParameters()[0]; // Property echo $testAsProperty->getAttributes()[0]->getTarget() === Attribute::TARGET_PROPERTY ? "Attribute targets property\n" : "Attribute does not target property\n"; // Parameter echo $testAsParemter->getAttributes()[0]->getTarget() === Attribute::TARGET_PARAMETER ? "Attribute targets parameter (why?)\n" : "Attribute does not target parameter\n";
Output for git.master_jit, git.master
Attribute targets property Attribute targets parameter (why?)

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:
28.45 ms | 405 KiB | 5 Q