PHP7_0.test 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. --TEST--
  2. PHP 7.0 test.
  3. --RULESET--
  4. {
  5. "@Symfony": true,
  6. "ordered_imports": true,
  7. "random_api_migration": true,
  8. "visibility_required": {"elements": ["property", "method"]}
  9. }
  10. --EXPECT--
  11. <?php
  12. // strict types
  13. declare(strict_types=1);
  14. // new imports
  15. use some\a\ClassA;
  16. use some\a\ClassB;
  17. use some\a\ClassC as C;
  18. use const some\a\ConstA;
  19. use const some\a\ConstB;
  20. use const some\a\ConstC;
  21. use function some\a\fn_a;
  22. use function some\a\fn_b;
  23. use function some\a\fn_c;
  24. use some\x\ClassX;
  25. use function some\x\D;
  26. use const some\x\E;
  27. function dummyUsage()
  28. {
  29. // class' class const
  30. echo ClassA::class.ClassB::class.ClassX::class.C::class.E;
  31. fn_a(fn_b(fn_c()));
  32. D();
  33. echo ConstA.ConstB.ConstC;
  34. }
  35. interface FooInterface
  36. {
  37. }
  38. class Foo implements FooInterface
  39. {
  40. // semi-reserved keyword as const
  41. const FOR = 1;
  42. // array const
  43. const ARR = [1, 2];
  44. // semi-reserved keyword as function name
  45. public function list($a, $b)
  46. {
  47. // combined comparison operator
  48. echo $a <=> $b;
  49. // isset ternary
  50. echo $a ?? $b;
  51. // new random generator
  52. echo mt_rand(0, 1);
  53. // uniform variable syntax
  54. $a = ['b' => 'c'];
  55. $c = 'Next step !';
  56. echo ${$a['b']};
  57. // uniform variable syntax on function
  58. $this->getFnc()();
  59. }
  60. // scalar typehinting
  61. public function bar1(int $a): string
  62. {
  63. }
  64. // scalar typehinting
  65. public function bar2(int $a): string
  66. {
  67. }
  68. public function getFnc1()
  69. {
  70. return function () {
  71. echo 1;
  72. };
  73. }
  74. public function getFnc2()
  75. {
  76. return function () { echo 1; };
  77. }
  78. public function gen1()
  79. {
  80. yield 1;
  81. // generator delegation
  82. yield from $this->gen2();
  83. }
  84. public function gen2()
  85. {
  86. yield 2;
  87. }
  88. }
  89. // anonymous class
  90. $message = (new class {});
  91. $message = (new class implements FooInterface {});
  92. if (1) {
  93. $message = (new class extends Foo {
  94. public function bar()
  95. {
  96. echo 1;
  97. }
  98. });
  99. }
  100. // unicode escape
  101. echo "\u{26C4}";
  102. --INPUT--
  103. <?php
  104. // strict types
  105. declare (strict_types = 1);
  106. // new imports
  107. use some\a\{ClassA, ClassB, ClassC as C};
  108. use function some\a\{fn_a, fn_b, fn_c};
  109. use const some\a\{ConstA, ConstB, ConstC};
  110. use some\x\{ClassX, function CC as C, function D, const E, function A\B};
  111. function dummyUsage()
  112. {
  113. // class' class const
  114. echo ClassA::class . ClassB::class . ClassX::class . C::class.E;
  115. fn_a(fn_b(fn_c())); D();
  116. echo ConstA . ConstB . ConstC;
  117. }
  118. interface FooInterface
  119. {
  120. }
  121. class Foo implements FooInterface
  122. {
  123. // semi-reserved keyword as const
  124. const FOR = 1;
  125. // array const
  126. const ARR = array(1, 2);
  127. // semi-reserved keyword as function name
  128. public function list($a,$b)
  129. {
  130. // combined comparison operator
  131. echo $a<=>$b;
  132. // isset ternary
  133. echo $a??$b;
  134. // new random generator
  135. echo rand(0, 1);
  136. // uniform variable syntax
  137. $a = array('b' => 'c');
  138. $c = 'Next step !';
  139. echo ${$a['b']};
  140. // uniform variable syntax on function
  141. $this->getFnc()();
  142. }
  143. // scalar typehinting
  144. public function bar1(int $a):string{}
  145. // scalar typehinting
  146. public function bar2(int $a) : string{}
  147. public function getFnc1()
  148. {
  149. return function () {
  150. echo 1; };
  151. }
  152. public function getFnc2()
  153. {
  154. return function () { echo 1; };
  155. }
  156. public function gen1()
  157. {
  158. yield 1;
  159. // generator delegation
  160. yield FROM $this->gen2();
  161. }
  162. public function gen2()
  163. {
  164. yield 2;
  165. }
  166. }
  167. // anonymous class
  168. $message = (new class {});
  169. $message = (new class() implements FooInterface {});
  170. if (1) {
  171. $message = (new class() extends Foo{ public function bar() { echo 1; } });
  172. }
  173. // unicode escape
  174. echo "\u{26C4}";