菜谱项目

ternaryAndCoalesce.test 2.9KB

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