arrayDestructuring.test 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. Array destructuring
  2. -----
  3. <?php
  4. [$a, $b] = [$c, $d];
  5. [, $a, , , $b, ,] = $foo;
  6. [, [[$a]], $b] = $bar;
  7. ['a' => $b, 'b' => $a] = $baz;
  8. -----
  9. !!php7
  10. array(
  11. 0: Stmt_Expression(
  12. expr: Expr_Assign(
  13. var: Expr_Array(
  14. items: array(
  15. 0: Expr_ArrayItem(
  16. key: null
  17. value: Expr_Variable(
  18. name: a
  19. )
  20. byRef: false
  21. )
  22. 1: Expr_ArrayItem(
  23. key: null
  24. value: Expr_Variable(
  25. name: b
  26. )
  27. byRef: false
  28. )
  29. )
  30. )
  31. expr: Expr_Array(
  32. items: array(
  33. 0: Expr_ArrayItem(
  34. key: null
  35. value: Expr_Variable(
  36. name: c
  37. )
  38. byRef: false
  39. )
  40. 1: Expr_ArrayItem(
  41. key: null
  42. value: Expr_Variable(
  43. name: d
  44. )
  45. byRef: false
  46. )
  47. )
  48. )
  49. )
  50. )
  51. 1: Stmt_Expression(
  52. expr: Expr_Assign(
  53. var: Expr_Array(
  54. items: array(
  55. 0: null
  56. 1: Expr_ArrayItem(
  57. key: null
  58. value: Expr_Variable(
  59. name: a
  60. )
  61. byRef: false
  62. )
  63. 2: null
  64. 3: null
  65. 4: Expr_ArrayItem(
  66. key: null
  67. value: Expr_Variable(
  68. name: b
  69. )
  70. byRef: false
  71. )
  72. 5: null
  73. )
  74. )
  75. expr: Expr_Variable(
  76. name: foo
  77. )
  78. )
  79. )
  80. 2: Stmt_Expression(
  81. expr: Expr_Assign(
  82. var: Expr_Array(
  83. items: array(
  84. 0: null
  85. 1: Expr_ArrayItem(
  86. key: null
  87. value: Expr_Array(
  88. items: array(
  89. 0: Expr_ArrayItem(
  90. key: null
  91. value: Expr_Array(
  92. items: array(
  93. 0: Expr_ArrayItem(
  94. key: null
  95. value: Expr_Variable(
  96. name: a
  97. )
  98. byRef: false
  99. )
  100. )
  101. )
  102. byRef: false
  103. )
  104. )
  105. )
  106. byRef: false
  107. )
  108. 2: Expr_ArrayItem(
  109. key: null
  110. value: Expr_Variable(
  111. name: b
  112. )
  113. byRef: false
  114. )
  115. )
  116. )
  117. expr: Expr_Variable(
  118. name: bar
  119. )
  120. )
  121. )
  122. 3: Stmt_Expression(
  123. expr: Expr_Assign(
  124. var: Expr_Array(
  125. items: array(
  126. 0: Expr_ArrayItem(
  127. key: Scalar_String(
  128. value: a
  129. )
  130. value: Expr_Variable(
  131. name: b
  132. )
  133. byRef: false
  134. )
  135. 1: Expr_ArrayItem(
  136. key: Scalar_String(
  137. value: b
  138. )
  139. value: Expr_Variable(
  140. name: a
  141. )
  142. byRef: false
  143. )
  144. )
  145. )
  146. expr: Expr_Variable(
  147. name: baz
  148. )
  149. )
  150. )
  151. )