expect_015.phpt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. --TEST--
  2. AST pretty-peinter
  3. --INI--
  4. zend.assertions=1
  5. assert.exception=0
  6. --FILE--
  7. <?php
  8. assert(0 && ($a = function () {
  9. global $a, $$b;
  10. static $c, $d = 0;
  11. unset($e);
  12. $x = isset($a) && !empty($b) || eval($c);
  13. $x = $a ? $b : $c;
  14. $x = $a ?: $c;
  15. $x = $a ?? $b;
  16. list($a, $b, $c) = [1, 2=>'x', 'z'=>'c'];
  17. @foo();
  18. $y = clone $x;
  19. yield 1 => 2;
  20. yield from $x;
  21. }));
  22. assert(0 && ($a = function &(array &$a, ?X $b = null) use ($c,&$d) : ?X {
  23. abstract class A extends B implements C, D {
  24. const X = 12;
  25. const Y = self::X, Z = "aaa";
  26. public $a = 1, $b;
  27. protected $c;
  28. static private $d = null;
  29. abstract function foo();
  30. static private function f1() {
  31. for ($i = 0, $j = 100; $i < $j; $i++, --$j) {
  32. $s[$i] = $a[$j];
  33. }
  34. foreach ($a as $key => &$val) {
  35. print "$key => $val\n";
  36. }
  37. while ($s[$i]) {
  38. $i++;
  39. }
  40. do {
  41. $i--;
  42. } while ($s[$i]);
  43. $x = foo($a + 1, 4, ...[1,2,3]);
  44. $x = ${$a . "_1"}();
  45. $x = A::foo();
  46. $x = ${$a . "_1"}::foo();
  47. $x = A::${$a . "_1"}();
  48. $x = $x->foo();
  49. $x = ${$a . "_1"}->foo();
  50. $x = $x->{$a . "_1"}();
  51. $x->a = C::C;
  52. ${$a . "_1"}->a = ${$a . "_1"}::C;
  53. $x->{a . "_1"} = C::C;
  54. $x = C::$z;
  55. $x = ${$a . "_1"}::$z;
  56. $x = C::${$z . "_1"};
  57. $x?->y;
  58. $x?->y();
  59. foo(bar: $x);
  60. }
  61. }
  62. }));
  63. assert(0 && ($a = function &(array &$a, X $b = null, int|float $c) use ($c,&$d) : X {
  64. final class A {
  65. final protected function f2() {
  66. if (!$x) {
  67. return 0;
  68. }
  69. if ($x == 1) {
  70. return 1;
  71. } else if ($x == 2) {
  72. return 2;
  73. } else if ($x == 3) {
  74. return 3;
  75. } else {
  76. if ($x == 9) {
  77. return 9;
  78. }
  79. L0:
  80. do {
  81. switch ($x) {
  82. case 4: break;
  83. case 5: continue;
  84. case 6: break 2;
  85. case 7: continue 2;
  86. case 8: goto L0;
  87. default: return;
  88. }
  89. } while (0);
  90. }
  91. }
  92. }
  93. }));
  94. assert(0 && ($a = function &(?array &$a, X $b = null) use ($c,&$d) : X {
  95. class A {
  96. use T1, T2 {
  97. T1::foo insteadof foo;
  98. T2::foo as bar;
  99. baz as public;
  100. ops as protected x;
  101. }
  102. use T3;
  103. }
  104. }));
  105. assert(0 && ($a = function &(array &...$a) {
  106. declare(A=1,B=2);
  107. try {
  108. $i++;
  109. } catch (MyException $e) {
  110. echo 1;
  111. } catch (Exception $e) {
  112. echo 2;
  113. } finally {
  114. echo 3;
  115. }
  116. }));
  117. assert(0 && ($a = function (): ?static {
  118. declare(C=1) { echo 1; }
  119. $x = '\'"`$a';
  120. $x = "'\"`$a";
  121. $x = `'"\`$a`;
  122. $x = "{$a}b";
  123. $x = "${a}b";
  124. $x = " {$foo->bar} ${$foo->bar} ";
  125. $x = " ${'---'} ";
  126. foo();
  127. \foo();
  128. namespace\foo();
  129. $x = foo;
  130. $x = \foo;
  131. $x = namespace\foo;
  132. $x = new foo();
  133. $x = new \foo();
  134. $x = new namespace\foo();
  135. if ($a) {
  136. } elseif ($b) {
  137. }
  138. if ($a); else;
  139. }));
  140. ?>
  141. --EXPECTF--
  142. Warning: assert(): assert(0 && ($a = function () {
  143. global $a;
  144. global $$b;
  145. static $c;
  146. static $d = 0;
  147. unset($e);
  148. $x = isset($a) && !empty($b) || eval($c);
  149. $x = $a ? $b : $c;
  150. $x = $a ?: $c;
  151. $x = $a ?? $b;
  152. [$a, $b, $c] = [1, 2 => 'x', 'z' => 'c'];
  153. @foo();
  154. $y = clone $x;
  155. yield 1 => 2;
  156. yield from $x;
  157. })) failed in %s on line %d
  158. Warning: assert(): assert(0 && ($a = function &(array &$a, ?X $b = null) use($c, &$d): ?X {
  159. abstract class A extends B implements C, D {
  160. public const X = 12;
  161. public const Y = self::X, Z = 'aaa';
  162. public $a = 1, $b;
  163. protected $c;
  164. private static $d = null;
  165. public abstract function foo();
  166. private static function f1() {
  167. for ($i = 0, $j = 100; $i < $j; $i++, --$j) {
  168. $s[$i] = $a[$j];
  169. }
  170. foreach ($a as $key => &$val) {
  171. print "$key => $val\n";
  172. }
  173. while ($s[$i]) {
  174. $i++;
  175. }
  176. do {
  177. $i--;
  178. } while ($s[$i]);
  179. $x = foo($a + 1, 4, ...[1, 2, 3]);
  180. $x = ${$a . '_1'}();
  181. $x = A::foo();
  182. $x = ${$a . '_1'}::foo();
  183. $x = A::${$a . '_1'}();
  184. $x = $x->foo();
  185. $x = ${$a . '_1'}->foo();
  186. $x = $x->{$a . '_1'}();
  187. $x->a = C::C;
  188. ${$a . '_1'}->a = ${$a . '_1'}::C;
  189. $x->{a . '_1'} = C::C;
  190. $x = C::$z;
  191. $x = ${$a . '_1'}::$z;
  192. $x = C::${$z . '_1'};
  193. $x?->y;
  194. $x?->y();
  195. foo(bar: $x);
  196. }
  197. }
  198. })) failed in %s on line %d
  199. Warning: assert(): assert(0 && ($a = function &(array &$a, X $b = null, int|float $c) use($c, &$d): X {
  200. final class A {
  201. protected final function f2() {
  202. if (!$x) {
  203. return 0;
  204. }
  205. if ($x == 1) {
  206. return 1;
  207. } else if ($x == 2) {
  208. return 2;
  209. } else if ($x == 3) {
  210. return 3;
  211. } else {
  212. if ($x == 9) {
  213. return 9;
  214. }
  215. L0:
  216. do {
  217. switch ($x) {
  218. case 4:
  219. break;
  220. case 5:
  221. continue;
  222. case 6:
  223. break 2;
  224. case 7:
  225. continue 2;
  226. case 8:
  227. goto L0;
  228. default:
  229. return;
  230. }
  231. } while (0);
  232. }
  233. }
  234. }
  235. })) failed in %s on line %d
  236. Warning: assert(): assert(0 && ($a = function &(?array &$a, X $b = null) use($c, &$d): X {
  237. class A {
  238. use T1, T2 {
  239. T1::foo insteadof foo;
  240. T2::foo as bar;
  241. baz as public;
  242. ops as protected x;
  243. }
  244. use T3;
  245. }
  246. })) failed in %s on line %d
  247. Warning: assert(): assert(0 && ($a = function &(array &...$a) {
  248. declare(A = 1, B = 2);
  249. try {
  250. $i++;
  251. } catch (MyException $e) {
  252. echo 1;
  253. } catch (Exception $e) {
  254. echo 2;
  255. } finally {
  256. echo 3;
  257. }
  258. })) failed in %s on line %d
  259. Warning: assert(): assert(0 && ($a = function (): ?static {
  260. declare(C = 1) {
  261. echo 1;
  262. }
  263. $x = '\'"`$a';
  264. $x = "'\"`$a";
  265. $x = `'"\`$a`;
  266. $x = "{$a}b";
  267. $x = "{$a}b";
  268. $x = " {$foo->bar} {${$foo->bar}} ";
  269. $x = " ${---} ";
  270. foo();
  271. \foo();
  272. namespace\foo();
  273. $x = foo;
  274. $x = \foo;
  275. $x = namespace\foo;
  276. $x = new foo();
  277. $x = new \foo();
  278. $x = new namespace\foo();
  279. if ($a) {
  280. } elseif ($b) {
  281. }
  282. if ($a) {
  283. } else {
  284. }
  285. })) failed in %s on line %d