expect_015.phpt 6.3 KB

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