ternaryAndCoalesce.test 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. Ternary operator
  2. -----
  3. <?php
  4. // ternary
  5. $a ? $b : $c;
  6. $a ?: $c;
  7. // precedence
  8. $a ? $b : $c ? $d : $e;
  9. $a ? $b : ($c ? $d : $e);
  10. // null coalesce
  11. $a ?? $b;
  12. $a ?? $b ?? $c;
  13. $a ?? $b ? $c : $d;
  14. $a && $b ?? $c;
  15. -----
  16. array(
  17. 0: Stmt_Expression(
  18. expr: Expr_Ternary(
  19. cond: Expr_Variable(
  20. name: a
  21. comments: array(
  22. 0: // ternary
  23. )
  24. )
  25. if: Expr_Variable(
  26. name: b
  27. )
  28. else: Expr_Variable(
  29. name: c
  30. )
  31. comments: array(
  32. 0: // ternary
  33. )
  34. )
  35. comments: array(
  36. 0: // ternary
  37. )
  38. )
  39. 1: Stmt_Expression(
  40. expr: Expr_Ternary(
  41. cond: Expr_Variable(
  42. name: a
  43. )
  44. if: null
  45. else: Expr_Variable(
  46. name: c
  47. )
  48. )
  49. )
  50. 2: Stmt_Expression(
  51. expr: Expr_Ternary(
  52. cond: Expr_Ternary(
  53. cond: Expr_Variable(
  54. name: a
  55. comments: array(
  56. 0: // precedence
  57. )
  58. )
  59. if: Expr_Variable(
  60. name: b
  61. )
  62. else: Expr_Variable(
  63. name: c
  64. )
  65. comments: array(
  66. 0: // precedence
  67. )
  68. )
  69. if: Expr_Variable(
  70. name: d
  71. )
  72. else: Expr_Variable(
  73. name: e
  74. )
  75. comments: array(
  76. 0: // precedence
  77. )
  78. )
  79. comments: array(
  80. 0: // precedence
  81. )
  82. )
  83. 3: Stmt_Expression(
  84. expr: Expr_Ternary(
  85. cond: Expr_Variable(
  86. name: a
  87. )
  88. if: Expr_Variable(
  89. name: b
  90. )
  91. else: Expr_Ternary(
  92. cond: Expr_Variable(
  93. name: c
  94. )
  95. if: Expr_Variable(
  96. name: d
  97. )
  98. else: Expr_Variable(
  99. name: e
  100. )
  101. )
  102. )
  103. )
  104. 4: Stmt_Expression(
  105. expr: Expr_BinaryOp_Coalesce(
  106. left: Expr_Variable(
  107. name: a
  108. comments: array(
  109. 0: // null coalesce
  110. )
  111. )
  112. right: Expr_Variable(
  113. name: b
  114. )
  115. comments: array(
  116. 0: // null coalesce
  117. )
  118. )
  119. comments: array(
  120. 0: // null coalesce
  121. )
  122. )
  123. 5: Stmt_Expression(
  124. expr: Expr_BinaryOp_Coalesce(
  125. left: Expr_Variable(
  126. name: a
  127. )
  128. right: Expr_BinaryOp_Coalesce(
  129. left: Expr_Variable(
  130. name: b
  131. )
  132. right: Expr_Variable(
  133. name: c
  134. )
  135. )
  136. )
  137. )
  138. 6: Stmt_Expression(
  139. expr: Expr_Ternary(
  140. cond: Expr_BinaryOp_Coalesce(
  141. left: Expr_Variable(
  142. name: a
  143. )
  144. right: Expr_Variable(
  145. name: b
  146. )
  147. )
  148. if: Expr_Variable(
  149. name: c
  150. )
  151. else: Expr_Variable(
  152. name: d
  153. )
  154. )
  155. )
  156. 7: Stmt_Expression(
  157. expr: Expr_BinaryOp_Coalesce(
  158. left: Expr_BinaryOp_BooleanAnd(
  159. left: Expr_Variable(
  160. name: a
  161. )
  162. right: Expr_Variable(
  163. name: b
  164. )
  165. )
  166. right: Expr_Variable(
  167. name: c
  168. )
  169. )
  170. )
  171. )