1--TEST-- 2Backtrace during attribute instance creation 3--FILE-- 4<?php 5 6#[Attribute] 7class MyAttribute { 8 public function __construct() { 9 debug_print_backtrace(); 10 var_dump(debug_backtrace()); 11 var_dump((new Exception)->getTrace()); 12 } 13} 14 15#[MyAttribute] 16class Test {} 17 18(new ReflectionClass(Test::class))->getAttributes()[0]->newInstance(); 19 20?> 21--EXPECTF-- 22#0 MyAttribute->__construct() called at [%s031_backtrace.php:12] 23#1 ReflectionAttribute->newInstance() called at [%s:%d] 24array(2) { 25 [0]=> 26 array(7) { 27 ["file"]=> 28 string(%d) "%s031_backtrace.php" 29 ["line"]=> 30 int(12) 31 ["function"]=> 32 string(11) "__construct" 33 ["class"]=> 34 string(11) "MyAttribute" 35 ["object"]=> 36 object(MyAttribute)#1 (0) { 37 } 38 ["type"]=> 39 string(2) "->" 40 ["args"]=> 41 array(0) { 42 } 43 } 44 [1]=> 45 array(7) { 46 ["file"]=> 47 string(%d) "%s" 48 ["line"]=> 49 int(%d) 50 ["function"]=> 51 string(11) "newInstance" 52 ["class"]=> 53 string(19) "ReflectionAttribute" 54 ["object"]=> 55 object(ReflectionAttribute)#2 (0) { 56 } 57 ["type"]=> 58 string(2) "->" 59 ["args"]=> 60 array(0) { 61 } 62 } 63} 64array(2) { 65 [0]=> 66 array(6) { 67 ["file"]=> 68 string(%d) "%s031_backtrace.php" 69 ["line"]=> 70 int(12) 71 ["function"]=> 72 string(11) "__construct" 73 ["class"]=> 74 string(11) "MyAttribute" 75 ["type"]=> 76 string(2) "->" 77 ["args"]=> 78 array(0) { 79 } 80 } 81 [1]=> 82 array(6) { 83 ["file"]=> 84 string(%d) "%s" 85 ["line"]=> 86 int(%d) 87 ["function"]=> 88 string(11) "newInstance" 89 ["class"]=> 90 string(19) "ReflectionAttribute" 91 ["type"]=> 92 string(2) "->" 93 ["args"]=> 94 array(0) { 95 } 96 } 97} 98