arrow_function.test 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. Arrow function
  2. -----
  3. <?php
  4. fn($a)
  5. =>
  6. $a;
  7. -----
  8. $stmts[0]->expr->expr = new Expr\Variable('b');
  9. -----
  10. <?php
  11. fn($a)
  12. =>
  13. $b;
  14. -----
  15. <?php
  16. fn(
  17. $a
  18. ) => $a;
  19. -----
  20. $stmts[0]->expr->params[] = new Node\Param(new Expr\Variable('b'));
  21. -----
  22. <?php
  23. fn(
  24. $a, $b
  25. ) => $a;
  26. -----
  27. <?php
  28. fn(
  29. $a
  30. )
  31. =>
  32. $a;
  33. -----
  34. // TODO: Format preserving currently not supported
  35. $stmts[0]->expr->params = [];
  36. -----
  37. <?php
  38. fn() => $a;
  39. -----
  40. <?php
  41. fn($a)
  42. : int
  43. => $a;
  44. -----
  45. $stmts[0]->expr->returnType = new Node\Identifier('bool');
  46. -----
  47. <?php
  48. fn($a)
  49. : bool
  50. => $a;
  51. -----
  52. <?php
  53. fn($a)
  54. : int
  55. => $a;
  56. -----
  57. $stmts[0]->expr->returnType = null;
  58. -----
  59. <?php
  60. fn($a)
  61. => $a;
  62. -----
  63. <?php
  64. fn($a)
  65. : int
  66. => $a;
  67. static fn($a)
  68. : int
  69. => $a;
  70. -----
  71. // TODO: Format preserving currently not supported
  72. $stmts[0]->expr->static = true;
  73. $stmts[1]->expr->static = false;
  74. -----
  75. <?php
  76. static fn($a): int => $a;
  77. fn($a): int => $a;
  78. -----
  79. <?php
  80. fn($a)
  81. : int
  82. => $a;
  83. fn&($a)
  84. : int
  85. => $a;
  86. -----
  87. // TODO: Format preserving currently not supported
  88. $stmts[0]->expr->byRef = true;
  89. $stmts[1]->expr->byRef = false;
  90. -----
  91. <?php
  92. fn&($a): int => $a;
  93. fn($a): int => $a;