1--TEST--
2Arrow functions ('fn($x) => $x') in PHP 7.4
3--SKIPIF--
4<?php if (PHP_VERSION_ID < 70400) die('skip PHP >= 7.4 only'); ?>
5--FILE--
6<?php
7
8require __DIR__ . '/../util.php';
9
10$code = <<<'PHP'
11<?php
12$y = 1;
13$a = fn($x) => $x * $y;
14$b = static fn() => 1;
15$c = /** doc comment */ static fn(?int... $args): array => $args;
16$fn = fn() => yield 123;
17PHP;
18
19$node = ast\parse_code($code, $version=70);
20$version_70_repr = ast_dump($node);
21echo $version_70_repr . "\n";
22$node50 = ast\parse_code($code, $version=50);
23$version_50_repr = ast_dump($node50);
24echo "Same representation in version 50/70: ";
25var_export($version_50_repr == $version_70_repr);
26echo "\n";
27?>
28--EXPECTF--
29AST_STMT_LIST
30    0: AST_ASSIGN
31        var: AST_VAR
32            name: "y"
33        expr: 1
34    1: AST_ASSIGN
35        var: AST_VAR
36            name: "a"
37        expr: AST_ARROW_FUNC
38            name: "{closure}"
39            docComment: null
40            params: AST_PARAM_LIST
41                0: AST_PARAM
42                    type: null
43                    name: "x"
44                    default: null
45            stmts: AST_RETURN
46                expr: AST_BINARY_OP
47                    flags: BINARY_MUL (%d)
48                    left: AST_VAR
49                        name: "x"
50                    right: AST_VAR
51                        name: "y"
52            returnType: null
53            __declId: 0
54    2: AST_ASSIGN
55        var: AST_VAR
56            name: "b"
57        expr: AST_ARROW_FUNC
58            flags: MODIFIER_STATIC (%d)
59            name: "{closure}"
60            docComment: null
61            params: AST_PARAM_LIST
62            stmts: AST_RETURN
63                expr: 1
64            returnType: null
65            __declId: 1
66    3: AST_ASSIGN
67        var: AST_VAR
68            name: "c"
69        expr: AST_ARROW_FUNC
70            flags: MODIFIER_STATIC (%d)
71            name: "{closure}"
72            docComment: "/** doc comment */"
73            params: AST_PARAM_LIST
74                0: AST_PARAM
75                    flags: PARAM_VARIADIC (%d)
76                    type: AST_NULLABLE_TYPE
77                        type: AST_TYPE
78                            flags: TYPE_LONG (%d)
79                    name: "args"
80                    default: null
81            stmts: AST_RETURN
82                expr: AST_VAR
83                    name: "args"
84            returnType: AST_TYPE
85                flags: TYPE_ARRAY (%d)
86            __declId: 2
87    4: AST_ASSIGN
88        var: AST_VAR
89            name: "fn"
90        expr: AST_ARROW_FUNC
91            flags: FUNC_GENERATOR (%d)
92            name: "{closure}"
93            docComment: null
94            params: AST_PARAM_LIST
95            stmts: AST_RETURN
96                expr: AST_YIELD
97                    value: 123
98                    key: null
99            returnType: null
100            __declId: 3
101
102Deprecated: ast\parse_code(): Version 50 is deprecated in %s.php on line 17
103Same representation in version 50/70: true