1--TEST-- 2Allow fetching properties in attributes 3--EXTENSIONS-- 4reflection 5--FILE-- 6<?php 7 8enum A: string { 9 case B = 'C'; 10} 11 12#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] 13class Attr { 14 public function __construct(public $value) {} 15} 16 17#[Attr(A::B->name)] 18#[Attr(A::B->value)] 19#[Attr(A::B?->name)] 20#[Attr(A::B?->value)] 21class C {} 22 23foreach ((new ReflectionClass(C::class))->getAttributes() as $reflectionAttribute) { 24 var_dump($reflectionAttribute->newInstance()); 25} 26 27?> 28--EXPECTF-- 29object(Attr)#%d (1) { 30 ["value"]=> 31 string(1) "B" 32} 33object(Attr)#%d (1) { 34 ["value"]=> 35 string(1) "C" 36} 37object(Attr)#%d (1) { 38 ["value"]=> 39 string(1) "B" 40} 41object(Attr)#%d (1) { 42 ["value"]=> 43 string(1) "C" 44} 45