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