match.test 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. Matches
  2. -----
  3. <?php
  4. $value = match (1)
  5. {
  6. 1
  7. =>
  8. 'one'
  9. };
  10. -----
  11. $stmts[0]->expr->expr->arms[] = new Node\MatchArm(null, new Scalar\String_('two'));
  12. -----
  13. <?php
  14. $value = match (1)
  15. {
  16. 1
  17. =>
  18. 'one',
  19. default => 'two'
  20. };
  21. -----
  22. <?php
  23. $value = match (1) {
  24. 1, 2 =>
  25. 'test',
  26. };
  27. -----
  28. $stmts[0]->expr->expr->arms[0]->conds[] = new Scalar\LNumber(3);
  29. -----
  30. <?php
  31. $value = match (1) {
  32. 1, 2, 3 =>
  33. 'test',
  34. };
  35. -----
  36. <?php
  37. $value = match (1) {
  38. 1
  39. =>
  40. 'one',
  41. 2
  42. =>
  43. 'two',
  44. 3
  45. =>
  46. 'three',
  47. };
  48. -----
  49. array_splice($stmts[0]->expr->expr->arms, 1, 1, []);
  50. -----
  51. <?php
  52. $value = match (1) {
  53. 1
  54. =>
  55. 'one',
  56. 3
  57. =>
  58. 'three',
  59. };
  60. -----
  61. <?php
  62. // TODO: Preserve formatting?
  63. $value = match (1) {
  64. default
  65. =>
  66. 'test',
  67. };
  68. -----
  69. $stmts[0]->expr->expr->arms[0]->conds = [new Scalar\LNumber(1)];
  70. -----
  71. <?php
  72. // TODO: Preserve formatting?
  73. $value = match (1) {
  74. 1 => 'test',
  75. };
  76. -----
  77. <?php
  78. // TODO: Preserve formatting?
  79. $value = match (1) {
  80. 1
  81. =>
  82. 'test',
  83. };
  84. -----
  85. $stmts[0]->expr->expr->arms[0]->conds = null;
  86. -----
  87. <?php
  88. // TODO: Preserve formatting?
  89. $value = match (1) {
  90. default => 'test',
  91. };