ternaryAndCoalesce.test 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. )
  22. if: Expr_Variable(
  23. name: b
  24. )
  25. else: Expr_Variable(
  26. name: c
  27. )
  28. )
  29. comments: array(
  30. 0: // ternary
  31. )
  32. )
  33. 1: Stmt_Expression(
  34. expr: Expr_Ternary(
  35. cond: Expr_Variable(
  36. name: a
  37. )
  38. if: null
  39. else: Expr_Variable(
  40. name: c
  41. )
  42. )
  43. )
  44. 2: Stmt_Expression(
  45. expr: Expr_Ternary(
  46. cond: Expr_Ternary(
  47. cond: Expr_Variable(
  48. name: a
  49. )
  50. if: Expr_Variable(
  51. name: b
  52. )
  53. else: Expr_Variable(
  54. name: c
  55. )
  56. )
  57. if: Expr_Variable(
  58. name: d
  59. )
  60. else: Expr_Variable(
  61. name: e
  62. )
  63. )
  64. comments: array(
  65. 0: // precedence
  66. )
  67. )
  68. 3: Stmt_Expression(
  69. expr: Expr_Ternary(
  70. cond: Expr_Variable(
  71. name: a
  72. )
  73. if: Expr_Variable(
  74. name: b
  75. )
  76. else: Expr_Ternary(
  77. cond: Expr_Variable(
  78. name: c
  79. )
  80. if: Expr_Variable(
  81. name: d
  82. )
  83. else: Expr_Variable(
  84. name: e
  85. )
  86. )
  87. )
  88. )
  89. 4: Stmt_Expression(
  90. expr: Expr_BinaryOp_Coalesce(
  91. left: Expr_Variable(
  92. name: a
  93. )
  94. right: Expr_Variable(
  95. name: b
  96. )
  97. )
  98. comments: array(
  99. 0: // null coalesce
  100. )
  101. )
  102. 5: Stmt_Expression(
  103. expr: Expr_BinaryOp_Coalesce(
  104. left: Expr_Variable(
  105. name: a
  106. )
  107. right: Expr_BinaryOp_Coalesce(
  108. left: Expr_Variable(
  109. name: b
  110. )
  111. right: Expr_Variable(
  112. name: c
  113. )
  114. )
  115. )
  116. )
  117. 6: Stmt_Expression(
  118. expr: Expr_Ternary(
  119. cond: Expr_BinaryOp_Coalesce(
  120. left: Expr_Variable(
  121. name: a
  122. )
  123. right: Expr_Variable(
  124. name: b
  125. )
  126. )
  127. if: Expr_Variable(
  128. name: c
  129. )
  130. else: Expr_Variable(
  131. name: d
  132. )
  133. )
  134. )
  135. 7: Stmt_Expression(
  136. expr: Expr_BinaryOp_Coalesce(
  137. left: Expr_BinaryOp_BooleanAnd(
  138. left: Expr_Variable(
  139. name: a
  140. )
  141. right: Expr_Variable(
  142. name: b
  143. )
  144. )
  145. right: Expr_Variable(
  146. name: c
  147. )
  148. )
  149. )
  150. )