Security update for Core, with self-updated composer
[yaffs-website] / vendor / nikic / php-parser / test / code / parser / errorHandling / recovery.test
1 Error recovery
2 -----
3 <?php
4
5 foo()
6 bar()
7 baz()
8 -----
9 Syntax error, unexpected T_STRING from 4:1 to 4:3
10 Syntax error, unexpected T_STRING from 5:1 to 5:3
11 Syntax error, unexpected EOF from 5:6 to 5:6
12 array(
13     0: Expr_FuncCall(
14         name: Name(
15             parts: array(
16                 0: foo
17             )
18         )
19         args: array(
20         )
21     )
22     1: Expr_FuncCall(
23         name: Name(
24             parts: array(
25                 0: bar
26             )
27         )
28         args: array(
29         )
30     )
31     2: Expr_FuncCall(
32         name: Name(
33             parts: array(
34                 0: baz
35             )
36         )
37         args: array(
38         )
39     )
40 )
41 -----
42 <?php
43
44 foo()
45 bar();
46 baz();
47 -----
48 Syntax error, unexpected T_STRING from 4:1 to 4:3
49 array(
50     0: Expr_FuncCall(
51         name: Name(
52             parts: array(
53                 0: foo
54             )
55         )
56         args: array(
57         )
58     )
59     1: Expr_FuncCall(
60         name: Name(
61             parts: array(
62                 0: bar
63             )
64         )
65         args: array(
66         )
67     )
68     2: Expr_FuncCall(
69         name: Name(
70             parts: array(
71                 0: baz
72             )
73         )
74         args: array(
75         )
76     )
77 )
78 -----
79 <?php
80
81 foo();
82 bar()
83 baz();
84 -----
85 Syntax error, unexpected T_STRING from 5:1 to 5:3
86 array(
87     0: Expr_FuncCall(
88         name: Name(
89             parts: array(
90                 0: foo
91             )
92         )
93         args: array(
94         )
95     )
96     1: Expr_FuncCall(
97         name: Name(
98             parts: array(
99                 0: bar
100             )
101         )
102         args: array(
103         )
104     )
105     2: Expr_FuncCall(
106         name: Name(
107             parts: array(
108                 0: baz
109             )
110         )
111         args: array(
112         )
113     )
114 )
115 -----
116 <?php
117 abc;
118 1 + ;
119 -----
120 Syntax error, unexpected ';' from 3:5 to 3:5
121 array(
122     0: Expr_ConstFetch(
123         name: Name(
124             parts: array(
125                 0: abc
126             )
127         )
128     )
129     1: Scalar_LNumber(
130         value: 1
131     )
132 )
133 -----
134 <?php
135 function test() {
136     1 +
137 }
138 -----
139 Syntax error, unexpected '}' from 4:1 to 4:1
140 array(
141     0: Stmt_Function(
142         byRef: false
143         name: test
144         params: array(
145         )
146         returnType: null
147         stmts: array(
148             0: Scalar_LNumber(
149                 value: 1
150             )
151         )
152     )
153 )
154 -----
155 <?php
156
157 $i = 0;
158 while
159
160 $j = 1;
161 $k = 2;
162 -----
163 Syntax error, unexpected T_VARIABLE, expecting '(' from 6:1 to 6:2
164 array(
165     0: Expr_Assign(
166         var: Expr_Variable(
167             name: i
168         )
169         expr: Scalar_LNumber(
170             value: 0
171         )
172     )
173     1: Expr_Assign(
174         var: Expr_Variable(
175             name: j
176         )
177         expr: Scalar_LNumber(
178             value: 1
179         )
180     )
181     2: Expr_Assign(
182         var: Expr_Variable(
183             name: k
184         )
185         expr: Scalar_LNumber(
186             value: 2
187         )
188     )
189 )
190 -----
191 <?php
192
193 $i = 0;
194 while () {
195     $j = 1;
196 }
197 $k = 2;
198 // The output here drops the loop - would require Error node to handle this
199 -----
200 Syntax error, unexpected ')' from 4:8 to 4:8
201 array(
202     0: Expr_Assign(
203         var: Expr_Variable(
204             name: i
205         )
206         expr: Scalar_LNumber(
207             value: 0
208         )
209     )
210     1: Expr_Assign(
211         var: Expr_Variable(
212             name: j
213         )
214         expr: Scalar_LNumber(
215             value: 1
216         )
217     )
218     2: Expr_Assign(
219         var: Expr_Variable(
220             name: k
221         )
222         expr: Scalar_LNumber(
223             value: 2
224         )
225     )
226     3: Stmt_Nop(
227         comments: array(
228             0: // The output here drops the loop - would require Error node to handle this
229         )
230     )
231 )
232 -----
233 <?php
234 // Can't recover this yet, as the '}' for the inner_statement_list
235 // is always required.
236
237 $i = 0;
238 while (true) {
239     $i = 1;
240     $i = 2;
241 -----
242 Syntax error, unexpected EOF from 8:12 to 8:12
243 -----
244 <?php
245 $foo->
246 ;
247 -----
248 !!positions
249 Syntax error, unexpected ';', expecting T_STRING or T_VARIABLE or '{' or '$' from 3:1 to 3:1
250 array(
251     0: Expr_PropertyFetch[2:1 - 2:6](
252         var: Expr_Variable[2:1 - 2:4](
253             name: foo
254         )
255         name: Expr_Error[3:1 - 2:6](
256         )
257     )
258 )
259 -----
260 <?php
261 function foo() {
262     $bar->
263 }
264 -----
265 !!positions
266 Syntax error, unexpected '}', expecting T_STRING or T_VARIABLE or '{' or '$' from 4:1 to 4:1
267 array(
268     0: Stmt_Function[2:1 - 4:1](
269         byRef: false
270         name: foo
271         params: array(
272         )
273         returnType: null
274         stmts: array(
275             0: Expr_PropertyFetch[3:5 - 3:10](
276                 var: Expr_Variable[3:5 - 3:8](
277                     name: bar
278                 )
279                 name: Expr_Error[4:1 - 3:10](
280                 )
281             )
282         )
283     )
284 )
285 -----
286 <?php
287 new T
288 -----
289 Syntax error, unexpected EOF from 2:6 to 2:6
290 array(
291     0: Expr_New(
292         class: Name(
293             parts: array(
294                 0: T
295             )
296         )
297         args: array(
298         )
299     )
300 )
301 -----
302 <?php
303 new
304 -----
305 !!php7,positions
306 Syntax error, unexpected EOF from 2:4 to 2:4
307 array(
308     0: Expr_New[2:1 - 2:3](
309         class: Expr_Error[2:4 - 2:3](
310         )
311         args: array(
312         )
313     )
314 )
315 -----
316 <?php
317 $foo instanceof
318 -----
319 !!php7
320 Syntax error, unexpected EOF from 2:16 to 2:16
321 array(
322     0: Expr_Instanceof(
323         expr: Expr_Variable(
324             name: foo
325         )
326         class: Expr_Error(
327         )
328     )
329 )
330 -----
331 <?php
332 $
333 -----
334 !!php7
335 Syntax error, unexpected EOF, expecting T_VARIABLE or '{' or '$' from 2:2 to 2:2
336 array(
337     0: Expr_Variable(
338         name: Expr_Error(
339         )
340     )
341 )
342 -----
343 <?php
344 Foo::$
345 -----
346 !!php7
347 Syntax error, unexpected EOF, expecting T_VARIABLE or '{' or '$' from 2:7 to 2:7
348 array(
349     0: Expr_StaticPropertyFetch(
350         class: Name(
351             parts: array(
352                 0: Foo
353             )
354         )
355         name: Expr_Error(
356         )
357     )
358 )
359 -----
360 <?php
361 Foo::
362 -----
363 !!php7
364 Syntax error, unexpected EOF from 2:6 to 2:6
365 array(
366     0: Expr_ClassConstFetch(
367         class: Name(
368             parts: array(
369                 0: Foo
370             )
371         )
372         name: Expr_Error(
373         )
374     )
375 )
376 -----
377 <?php
378 namespace Foo
379 use A
380 use function a
381 use A\{B}
382 const A = 1
383 break
384 break 2
385 continue
386 continue 2
387 return
388 return 2
389 echo $a
390 unset($a)
391 throw $x
392 goto label
393 -----
394 !!php7
395 Syntax error, unexpected T_USE, expecting ';' or '{' from 3:1 to 3:3
396 Syntax error, unexpected T_USE, expecting ';' from 5:1 to 5:3
397 Syntax error, unexpected T_CONST, expecting ';' from 6:1 to 6:5
398 Syntax error, unexpected T_BREAK, expecting ';' from 7:1 to 7:5
399 Syntax error, unexpected T_THROW, expecting ';' from 15:1 to 15:5
400 array(
401     0: Stmt_Namespace(
402         name: Name(
403             parts: array(
404                 0: Foo
405             )
406         )
407         stmts: array(
408             0: Stmt_Use(
409                 type: TYPE_NORMAL (1)
410                 uses: array(
411                     0: Stmt_UseUse(
412                         type: TYPE_UNKNOWN (0)
413                         name: Name(
414                             parts: array(
415                                 0: A
416                             )
417                         )
418                         alias: A
419                     )
420                 )
421             )
422             1: Stmt_Use(
423                 type: TYPE_FUNCTION (2)
424                 uses: array(
425                     0: Stmt_UseUse(
426                         type: TYPE_UNKNOWN (0)
427                         name: Name(
428                             parts: array(
429                                 0: a
430                             )
431                         )
432                         alias: a
433                     )
434                 )
435             )
436             2: Stmt_GroupUse(
437                 type: TYPE_UNKNOWN (0)
438                 prefix: Name(
439                     parts: array(
440                         0: A
441                     )
442                 )
443                 uses: array(
444                     0: Stmt_UseUse(
445                         type: TYPE_NORMAL (1)
446                         name: Name(
447                             parts: array(
448                                 0: B
449                             )
450                         )
451                         alias: B
452                     )
453                 )
454             )
455             3: Stmt_Const(
456                 consts: array(
457                     0: Const(
458                         name: A
459                         value: Scalar_LNumber(
460                             value: 1
461                         )
462                     )
463                 )
464             )
465             4: Stmt_Break(
466                 num: null
467             )
468             5: Stmt_Break(
469                 num: Scalar_LNumber(
470                     value: 2
471                 )
472             )
473             6: Stmt_Continue(
474                 num: null
475             )
476             7: Stmt_Continue(
477                 num: Scalar_LNumber(
478                     value: 2
479                 )
480             )
481             8: Stmt_Return(
482                 expr: null
483             )
484             9: Stmt_Return(
485                 expr: Scalar_LNumber(
486                     value: 2
487                 )
488             )
489             10: Stmt_Echo(
490                 exprs: array(
491                     0: Expr_Variable(
492                         name: a
493                     )
494                 )
495             )
496             11: Stmt_Unset(
497                 vars: array(
498                     0: Expr_Variable(
499                         name: a
500                     )
501                 )
502             )
503             12: Stmt_Throw(
504                 expr: Expr_Variable(
505                     name: x
506                 )
507             )
508             13: Stmt_Goto(
509                 name: label
510             )
511         )
512     )
513 )
514 -----
515 <?php
516
517 use A\{B, };
518 use function A\{b, };
519 use A, ;
520 const A = 42, ;
521
522 class X implements Y, {
523     use A, ;
524     use A, {
525         A::b insteadof C, ;
526     }
527     const A = 42, ;
528     public $x, ;
529 }
530 interface I extends J, {}
531
532 unset($x, );
533 isset($x, );
534
535 declare(a=42, );
536
537 function foo($a, ) {}
538 foo($a, );
539 global $a, ;
540 static $a, ;
541 echo $a, ;
542
543 for ($a, ; $b, ; $c, );
544 function ($a, ) use ($b, ) {};
545 -----
546 !!php7
547 A trailing comma is not allowed here from 5:6 to 5:6
548 A trailing comma is not allowed here from 6:13 to 6:13
549 A trailing comma is not allowed here from 8:21 to 8:21
550 A trailing comma is not allowed here from 9:10 to 9:10
551 A trailing comma is not allowed here from 10:10 to 10:10
552 A trailing comma is not allowed here from 11:25 to 11:25
553 A trailing comma is not allowed here from 13:17 to 13:17
554 A trailing comma is not allowed here from 14:14 to 14:14
555 A trailing comma is not allowed here from 16:22 to 16:22
556 A trailing comma is not allowed here from 18:9 to 18:9
557 A trailing comma is not allowed here from 19:9 to 19:9
558 A trailing comma is not allowed here from 21:13 to 21:13
559 A trailing comma is not allowed here from 23:16 to 23:16
560 A trailing comma is not allowed here from 24:7 to 24:7
561 A trailing comma is not allowed here from 25:10 to 25:10
562 A trailing comma is not allowed here from 26:10 to 26:10
563 A trailing comma is not allowed here from 27:8 to 27:8
564 A trailing comma is not allowed here from 29:8 to 29:8
565 A trailing comma is not allowed here from 29:14 to 29:14
566 A trailing comma is not allowed here from 29:20 to 29:20
567 A trailing comma is not allowed here from 30:13 to 30:13
568 A trailing comma is not allowed here from 30:24 to 30:24
569 array(
570     0: Stmt_GroupUse(
571         type: TYPE_UNKNOWN (0)
572         prefix: Name(
573             parts: array(
574                 0: A
575             )
576         )
577         uses: array(
578             0: Stmt_UseUse(
579                 type: TYPE_NORMAL (1)
580                 name: Name(
581                     parts: array(
582                         0: B
583                     )
584                 )
585                 alias: B
586             )
587         )
588     )
589     1: Stmt_GroupUse(
590         type: TYPE_FUNCTION (2)
591         prefix: Name(
592             parts: array(
593                 0: A
594             )
595         )
596         uses: array(
597             0: Stmt_UseUse(
598                 type: TYPE_UNKNOWN (0)
599                 name: Name(
600                     parts: array(
601                         0: b
602                     )
603                 )
604                 alias: b
605             )
606         )
607     )
608     2: Stmt_Use(
609         type: TYPE_NORMAL (1)
610         uses: array(
611             0: Stmt_UseUse(
612                 type: TYPE_UNKNOWN (0)
613                 name: Name(
614                     parts: array(
615                         0: A
616                     )
617                 )
618                 alias: A
619             )
620         )
621     )
622     3: Stmt_Const(
623         consts: array(
624             0: Const(
625                 name: A
626                 value: Scalar_LNumber(
627                     value: 42
628                 )
629             )
630         )
631     )
632     4: Stmt_Class(
633         flags: 0
634         name: X
635         extends: null
636         implements: array(
637             0: Name(
638                 parts: array(
639                     0: Y
640                 )
641             )
642         )
643         stmts: array(
644             0: Stmt_TraitUse(
645                 traits: array(
646                     0: Name(
647                         parts: array(
648                             0: A
649                         )
650                     )
651                 )
652                 adaptations: array(
653                 )
654             )
655             1: Stmt_TraitUse(
656                 traits: array(
657                     0: Name(
658                         parts: array(
659                             0: A
660                         )
661                     )
662                 )
663                 adaptations: array(
664                     0: Stmt_TraitUseAdaptation_Precedence(
665                         trait: Name(
666                             parts: array(
667                                 0: A
668                             )
669                         )
670                         method: b
671                         insteadof: array(
672                             0: Name(
673                                 parts: array(
674                                     0: C
675                                 )
676                             )
677                         )
678                     )
679                 )
680             )
681             2: Stmt_ClassConst(
682                 flags: 0
683                 consts: array(
684                     0: Const(
685                         name: A
686                         value: Scalar_LNumber(
687                             value: 42
688                         )
689                     )
690                 )
691             )
692             3: Stmt_Property(
693                 flags: MODIFIER_PUBLIC (1)
694                 props: array(
695                     0: Stmt_PropertyProperty(
696                         name: x
697                         default: null
698                     )
699                 )
700             )
701         )
702     )
703     5: Stmt_Interface(
704         name: I
705         extends: array(
706             0: Name(
707                 parts: array(
708                     0: J
709                 )
710             )
711         )
712         stmts: array(
713         )
714     )
715     6: Stmt_Unset(
716         vars: array(
717             0: Expr_Variable(
718                 name: x
719             )
720         )
721     )
722     7: Expr_Isset(
723         vars: array(
724             0: Expr_Variable(
725                 name: x
726             )
727         )
728     )
729     8: Stmt_Declare(
730         declares: array(
731             0: Stmt_DeclareDeclare(
732                 key: a
733                 value: Scalar_LNumber(
734                     value: 42
735                 )
736             )
737         )
738         stmts: null
739     )
740     9: Stmt_Function(
741         byRef: false
742         name: foo
743         params: array(
744             0: Param(
745                 type: null
746                 byRef: false
747                 variadic: false
748                 name: a
749                 default: null
750             )
751         )
752         returnType: null
753         stmts: array(
754         )
755     )
756     10: Expr_FuncCall(
757         name: Name(
758             parts: array(
759                 0: foo
760             )
761         )
762         args: array(
763             0: Arg(
764                 value: Expr_Variable(
765                     name: a
766                 )
767                 byRef: false
768                 unpack: false
769             )
770         )
771     )
772     11: Stmt_Global(
773         vars: array(
774             0: Expr_Variable(
775                 name: a
776             )
777         )
778     )
779     12: Stmt_Static(
780         vars: array(
781             0: Stmt_StaticVar(
782                 name: a
783                 default: null
784             )
785         )
786     )
787     13: Stmt_Echo(
788         exprs: array(
789             0: Expr_Variable(
790                 name: a
791             )
792         )
793     )
794     14: Stmt_For(
795         init: array(
796             0: Expr_Variable(
797                 name: a
798             )
799         )
800         cond: array(
801             0: Expr_Variable(
802                 name: b
803             )
804         )
805         loop: array(
806             0: Expr_Variable(
807                 name: c
808             )
809         )
810         stmts: array(
811         )
812     )
813     15: Expr_Closure(
814         static: false
815         byRef: false
816         params: array(
817             0: Param(
818                 type: null
819                 byRef: false
820                 variadic: false
821                 name: a
822                 default: null
823             )
824         )
825         uses: array(
826             0: Expr_ClosureUse(
827                 var: b
828                 byRef: false
829             )
830         )
831         returnType: null
832         stmts: array(
833         )
834     )
835 )
836 -----
837 <?php
838
839 foo(Bar::);
840 -----
841 !!php7,positions
842 Syntax error, unexpected ')' from 3:10 to 3:10
843 array(
844     0: Expr_FuncCall[3:1 - 3:10](
845         name: Name[3:1 - 3:3](
846             parts: array(
847                 0: foo
848             )
849         )
850         args: array(
851             0: Arg[3:5 - 3:9](
852                 value: Expr_ClassConstFetch[3:5 - 3:9](
853                     class: Name[3:5 - 3:7](
854                         parts: array(
855                             0: Bar
856                         )
857                     )
858                     name: Expr_Error[3:10 - 3:9](
859                     )
860                 )
861                 byRef: false
862                 unpack: false
863             )
864         )
865     )
866 )