1--TEST-- 2Attributes can be placed on all supported elements. 3--FILE-- 4<?php 5 6#[A1(1)] 7class Foo 8{ 9 #[A1(2)] 10 public const FOO = 'foo'; 11 12 #[A1(3)] 13 public $x; 14 15 #[A1(4)] 16 public function foo(#[A1(5)] $a, #[A1(6)] $b) { } 17} 18 19$object = new #[A1(7)] class () { }; 20 21#[A1(8)] 22function f1() { } 23 24$f2 = #[A1(9)] function () { }; 25 26$f3 = #[A1(10)] fn () => 1; 27 28$ref = new \ReflectionClass(Foo::class); 29 30$sources = [ 31 $ref, 32 $ref->getReflectionConstant('FOO'), 33 $ref->getProperty('x'), 34 $ref->getMethod('foo'), 35 $ref->getMethod('foo')->getParameters()[0], 36 $ref->getMethod('foo')->getParameters()[1], 37 new \ReflectionObject($object), 38 new \ReflectionFunction('f1'), 39 new \ReflectionFunction($f2), 40 new \ReflectionFunction($f3) 41]; 42 43foreach ($sources as $r) { 44 $attr = $r->getAttributes(); 45 var_dump(get_class($r), count($attr)); 46 47 foreach ($attr as $a) { 48 var_dump($a->getName(), $a->getArguments()); 49 } 50 51 echo "\n"; 52} 53 54?> 55--EXPECT-- 56string(15) "ReflectionClass" 57int(1) 58string(2) "A1" 59array(1) { 60 [0]=> 61 int(1) 62} 63 64string(23) "ReflectionClassConstant" 65int(1) 66string(2) "A1" 67array(1) { 68 [0]=> 69 int(2) 70} 71 72string(18) "ReflectionProperty" 73int(1) 74string(2) "A1" 75array(1) { 76 [0]=> 77 int(3) 78} 79 80string(16) "ReflectionMethod" 81int(1) 82string(2) "A1" 83array(1) { 84 [0]=> 85 int(4) 86} 87 88string(19) "ReflectionParameter" 89int(1) 90string(2) "A1" 91array(1) { 92 [0]=> 93 int(5) 94} 95 96string(19) "ReflectionParameter" 97int(1) 98string(2) "A1" 99array(1) { 100 [0]=> 101 int(6) 102} 103 104string(16) "ReflectionObject" 105int(1) 106string(2) "A1" 107array(1) { 108 [0]=> 109 int(7) 110} 111 112string(18) "ReflectionFunction" 113int(1) 114string(2) "A1" 115array(1) { 116 [0]=> 117 int(8) 118} 119 120string(18) "ReflectionFunction" 121int(1) 122string(2) "A1" 123array(1) { 124 [0]=> 125 int(9) 126} 127 128string(18) "ReflectionFunction" 129int(1) 130string(2) "A1" 131array(1) { 132 [0]=> 133 int(10) 134} 135