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