arrow_function.test 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. $stmts[0]->expr->static = true;
  72. $stmts[1]->expr->static = false;
  73. -----
  74. <?php
  75. static fn($a)
  76. : int
  77. => $a;
  78. fn($a)
  79. : int
  80. => $a;
  81. -----
  82. <?php
  83. fn($a)
  84. : int
  85. => $a;
  86. fn&($a)
  87. : int
  88. => $a;
  89. -----
  90. // TODO: Format preserving currently not supported
  91. $stmts[0]->expr->byRef = true;
  92. $stmts[1]->expr->byRef = false;
  93. -----
  94. <?php
  95. fn&($a): int => $a;
  96. fn($a): int => $a;