菜谱项目

arrayDestructuring.test 3.8KB

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