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 %s031_backtrace.php(12): MyAttribute->__construct()
23#1 %s(%d): ReflectionAttribute->newInstance()
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 (1) {
56      ["name"]=>
57      string(11) "MyAttribute"
58    }
59    ["type"]=>
60    string(2) "->"
61    ["args"]=>
62    array(0) {
63    }
64  }
65}
66array(2) {
67  [0]=>
68  array(6) {
69    ["file"]=>
70    string(%d) "%s031_backtrace.php"
71    ["line"]=>
72    int(12)
73    ["function"]=>
74    string(11) "__construct"
75    ["class"]=>
76    string(11) "MyAttribute"
77    ["type"]=>
78    string(2) "->"
79    ["args"]=>
80    array(0) {
81    }
82  }
83  [1]=>
84  array(6) {
85    ["file"]=>
86    string(%d) "%s"
87    ["line"]=>
88    int(%d)
89    ["function"]=>
90    string(11) "newInstance"
91    ["class"]=>
92    string(19) "ReflectionAttribute"
93    ["type"]=>
94    string(2) "->"
95    ["args"]=>
96    array(0) {
97    }
98  }
99}
100