outsideStmtInvalid.test 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 from 4:1 to 4:9
  9. array(
  10. 0: Stmt_Echo(
  11. exprs: array(
  12. 0: Scalar_Int(
  13. value: 1
  14. )
  15. )
  16. )
  17. 1: Stmt_Echo(
  18. exprs: array(
  19. 0: Scalar_Int(
  20. value: 2
  21. )
  22. )
  23. )
  24. 2: Stmt_Namespace(
  25. name: Name(
  26. name: A
  27. )
  28. stmts: array(
  29. )
  30. )
  31. )
  32. -----
  33. <?php
  34. namespace A {}
  35. echo 1;
  36. -----
  37. No code may exist outside of namespace {} from 3:1 to 3:7
  38. array(
  39. 0: Stmt_Namespace(
  40. name: Name(
  41. name: A
  42. )
  43. stmts: array(
  44. )
  45. )
  46. 1: Stmt_Echo(
  47. exprs: array(
  48. 0: Scalar_Int(
  49. value: 1
  50. )
  51. )
  52. )
  53. )
  54. -----
  55. <?php
  56. namespace A {}
  57. declare(ticks=1);
  58. foo();
  59. namespace B {}
  60. -----
  61. No code may exist outside of namespace {} from 3:1 to 3:17
  62. array(
  63. 0: Stmt_Namespace(
  64. name: Name(
  65. name: A
  66. )
  67. stmts: array(
  68. )
  69. )
  70. 1: Stmt_Declare(
  71. declares: array(
  72. 0: DeclareItem(
  73. key: Identifier(
  74. name: ticks
  75. )
  76. value: Scalar_Int(
  77. value: 1
  78. )
  79. )
  80. )
  81. stmts: null
  82. )
  83. 2: Stmt_Expression(
  84. expr: Expr_FuncCall(
  85. name: Name(
  86. name: foo
  87. )
  88. args: array(
  89. )
  90. )
  91. )
  92. 3: Stmt_Namespace(
  93. name: Name(
  94. name: B
  95. )
  96. stmts: array(
  97. )
  98. )
  99. )