031_backtrace.phpt 1.6 KB

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