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