match.test 1.1 KB

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