xref: /PHP-7.4/Zend/tests/assert/expect_015.phpt (revision fac43d65)
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    if ($a); else;
144}));
145
146?>
147--EXPECTF--
148Warning: assert(): assert(0 && ($a = function () {
149    global $a;
150    global $$b;
151    static $c;
152    static $d = 0;
153    unset($e);
154    $x = isset($a) && !empty($b) || eval($c);
155    $x = $a ? $b : $c;
156    $x = $a ?: $c;
157    $x = $a ?? $b;
158    [$a, $b, $c] = [1, 2 => 'x', 'z' => 'c'];
159    @foo();
160    $y = clone $x;
161    yield 1 => 2;
162    yield from $x;
163})) failed in %sexpect_015.php on line %d
164
165Warning: assert(): assert(0 && ($a = function &(array &$a, ?X $b = null) use($c, &$d): ?X {
166    abstract class A extends B implements C, D {
167        const X = 12;
168        const Y = self::X, Z = 'aaa';
169        public $a = 1, $b;
170        protected $c;
171        private static $d = null;
172        public abstract function foo();
173
174        private static function f1() {
175            for ($i = 0, $j = 100; $i < $j; $i++, --$j) {
176                $s[$i] = $a[$j];
177            }
178            foreach ($a as $key => &$val) {
179                print "$key => $val\n";
180            }
181            while ($s[$i]) {
182                $i++;
183            }
184            do {
185                $i--;
186            } while ($s[$i]);
187            $x = foo($a + 1, 4, ...[1, 2, 3]);
188            $x = ${$a . '_1'}();
189            $x = A::foo();
190            $x = ${$a . '_1'}::foo();
191            $x = A::${$a . '_1'}();
192            $x = $x->foo();
193            $x = ${$a . '_1'}->foo();
194            $x = $x->{$a . '_1'}();
195            $x->a = C::C;
196            ${$a . '_1'}->a = ${$a . '_1'}::C;
197            $x->{a . '_1'} = C::C;
198            $x = C::$z;
199            $x = ${$a . '_1'}::$z;
200            $x = C::${$z . '_1'};
201        }
202
203    }
204
205})) failed in %sexpect_015.php on line %d
206
207Warning: assert(): assert(0 && ($a = function &(array &$a, X $b = null) use($c, &$d): X {
208    final class A {
209        protected final function f2() {
210            if (!$x) {
211                return 0;
212            }
213            if ($x == 1) {
214                return 1;
215            } else if ($x == 2) {
216                return 2;
217            } else if ($x == 3) {
218                return 3;
219            } else {
220                if ($x == 9) {
221                    return 9;
222                }
223                L0:
224                do {
225                    switch ($x) {
226                        case 4:
227                            break;
228                        case 5:
229                            continue;
230                        case 6:
231                            break 2;
232                        case 7:
233                            continue 2;
234                        case 8:
235                            goto L0;
236                        default:
237                            return;
238                    }
239                } while (0);
240            }
241        }
242
243    }
244
245})) failed in %sexpect_015.php on line %d
246
247Warning: assert(): assert(0 && ($a = function &(?array &$a, X $b = null) use($c, &$d): X {
248    class A {
249        use T1, T2 {
250            T1::foo insteadof foo;
251            T2::foo as bar;
252            baz as public;
253            ops as protected x;
254        }
255        use T3;
256    }
257
258})) failed in %sexpect_015.php on line %d
259
260Warning: assert(): assert(0 && ($a = function &(array &...$a) {
261    declare(A = 1, B = 2);
262    try {
263        $i++;
264    } catch (MyException $e) {
265        echo 1;
266    } catch (Exception $e) {
267        echo 2;
268    } finally {
269        echo 3;
270    }
271})) failed in %sexpect_015.php on line %d
272
273Warning: assert(): assert(0 && ($a = function () {
274    declare(C = 1) {
275        echo 1;
276    }
277    $x = '\'"`$a';
278    $x = "'\"`$a";
279    $x = `'"\`$a`;
280    $x = "{$a}b";
281    $x = "{$a}b";
282    $x = " {$foo->bar} {${$foo->bar}} ";
283    $x = " ${---} ";
284    foo();
285    \foo();
286    namespace\foo();
287    $x = foo;
288    $x = \foo;
289    $x = namespace\foo;
290    $x = new foo();
291    $x = new \foo();
292    $x = new namespace\foo();
293    if ($a) {
294    } elseif ($b) {
295    }
296    if ($a) {
297    } else {
298    }
299})) failed in %sexpect_015.php on line %d
300