菜谱项目

outsideStmtInvalid.test 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. There (mostly) can't be statements outside of namespaces
  2. -----
  3. <?php
  4. echo 1;
  5. echo 2;
  6. namespace A;
  7. -----
  8. Namespace declaration statement has to be the very first statement in the script on line 4
  9. array(
  10. 0: Stmt_Echo(
  11. exprs: array(
  12. 0: Scalar_LNumber(
  13. value: 1
  14. )
  15. )
  16. )
  17. 1: Stmt_Echo(
  18. exprs: array(
  19. 0: Scalar_LNumber(
  20. value: 2
  21. )
  22. )
  23. )
  24. 2: Stmt_Namespace(
  25. name: Name(
  26. parts: array(
  27. 0: A
  28. )
  29. )
  30. stmts: array(
  31. )
  32. )
  33. )
  34. -----
  35. <?php
  36. namespace A {}
  37. echo 1;
  38. -----
  39. No code may exist outside of namespace {} from 3:1 to 3:7
  40. array(
  41. 0: Stmt_Namespace(
  42. name: Name(
  43. parts: array(
  44. 0: A
  45. )
  46. )
  47. stmts: array(
  48. )
  49. )
  50. 1: Stmt_Echo(
  51. exprs: array(
  52. 0: Scalar_LNumber(
  53. value: 1
  54. )
  55. )
  56. )
  57. )
  58. -----
  59. <?php
  60. namespace A {}
  61. declare(ticks=1);
  62. foo();
  63. namespace B {}
  64. -----
  65. No code may exist outside of namespace {} from 3:1 to 3:17
  66. array(
  67. 0: Stmt_Namespace(
  68. name: Name(
  69. parts: array(
  70. 0: A
  71. )
  72. )
  73. stmts: array(
  74. )
  75. )
  76. 1: Stmt_Declare(
  77. declares: array(
  78. 0: Stmt_DeclareDeclare(
  79. key: ticks
  80. value: Scalar_LNumber(
  81. value: 1
  82. )
  83. )
  84. )
  85. stmts: null
  86. )
  87. 2: Expr_FuncCall(
  88. name: Name(
  89. parts: array(
  90. 0: foo
  91. )
  92. )
  93. args: array(
  94. )
  95. )
  96. 3: Stmt_Namespace(
  97. name: Name(
  98. parts: array(
  99. 0: B
  100. )
  101. )
  102. stmts: array(
  103. )
  104. )
  105. )