3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[Attribute] class BaseAttribute { public function __construct(public readonly string $name) { } } #[Attribute] class ConstantlyNameAttribute extends BaseAttribute { public function __construct() { parent::__construct('Chris'); } } #[ConstantlyNameAttribute] class Thing{} $reflectionClass = new ReflectionClass(Thing::class); // Doesn't work var_dump(getName($reflectionClass->getAttributes(BaseAttribute::class))); // Works var_dump(getName($reflectionClass->getAttributes(BaseAttribute::class, ReflectionAttribute::IS_INSTANCEOF))); // Helper function function getName(array $reflectionAttributes) : ?string { if(!count($reflectionAttributes)){ return null; } $attribute = array_pop($reflectionAttributes); return $attribute->newInstance()->name; }
Output for git.master_jit, git.master
NULL string(5) "Chris"

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