@@ -39,12 +39,12 @@ Usage
39
39
40
40
Code can be parsed using either ` ast\parse_code() ` , which accepts a code string, or
41
41
` ast\parse_file() ` , which accepts a file path. Additionally both functions require a ` $version `
42
- argument to ensure forward-compatibility. The current version is 20 .
42
+ argument to ensure forward-compatibility. The current version is 30 .
43
43
44
44
``` php
45
- $ast = ast\parse_code('<?php ...', $version=20 );
45
+ $ast = ast\parse_code('<?php ...', $version=30 );
46
46
// or
47
- $ast = ast\parse_file('file.php', $version=20 );
47
+ $ast = ast\parse_file('file.php', $version=30 );
48
48
```
49
49
50
50
The abstract syntax tree returned by these functions consists of ` ast\Node ` objects.
@@ -102,7 +102,7 @@ $code = <<<'EOC'
102
102
$var = 42;
103
103
EOC;
104
104
105
- var_dump(ast\parse_code($code, $version=20 ));
105
+ var_dump(ast\parse_code($code, $version=30 ));
106
106
107
107
// Output:
108
108
object(ast\Node)#1 (4) {
@@ -121,24 +121,24 @@ object(ast\Node)#1 (4) {
121
121
["flags"]=>
122
122
int(0)
123
123
["lineno"]=>
124
- int(1 )
124
+ int(2 )
125
125
["children"]=>
126
126
array(2) {
127
- [0 ]=>
127
+ ["var" ]=>
128
128
object(ast\Node)#3 (4) {
129
129
["kind"]=>
130
130
int(256)
131
131
["flags"]=>
132
132
int(0)
133
133
["lineno"]=>
134
- int(1 )
134
+ int(2 )
135
135
["children"]=>
136
136
array(1) {
137
- [0 ]=>
137
+ ["name" ]=>
138
138
string(3) "var"
139
139
}
140
140
}
141
- [1 ]=>
141
+ ["expr" ]=>
142
142
int(42)
143
143
}
144
144
}
@@ -159,14 +159,14 @@ $code = <<<'EOC'
159
159
$var = 42;
160
160
EOC;
161
161
162
- echo ast_dump(ast\parse_code($code, $version=20 )), "\n";
162
+ echo ast_dump(ast\parse_code($code, $version=30 )), "\n";
163
163
164
164
// Output:
165
165
AST_STMT_LIST
166
166
0: AST_ASSIGN
167
- 0 : AST_VAR
168
- 0 : "var"
169
- 1 : 42
167
+ var : AST_VAR
168
+ name : "var"
169
+ expr : 42
170
170
```
171
171
172
172
To additionally show line numbers pass the ` AST_DUMP_LINENOS ` option as the second argument to
@@ -304,11 +304,11 @@ ast\flags\EXEC_REQUIRE_ONCE
304
304
Version changelog
305
305
-----------------
306
306
307
- ### 30 (unstable )
307
+ ### 30 (current )
308
308
309
309
* Use string names for child nodes of kinds with fixed length.
310
310
311
- ### 20 (current )
311
+ ### 20 (supported )
312
312
313
313
* ` AST_GREATER ` , ` AST_GREATER_EQUAL ` , ` AST_OR ` , ` AST_AND ` nodes are now represented using
314
314
` AST_BINARY_OP ` with flags ` BINARY_IS_GREATER ` , ` BINARY_IS_GREATER_OR_EQUAL ` , ` BINARY_BOOL_OR `
0 commit comments