@@ -37,12 +37,12 @@ Usage
37
37
38
38
Code can be parsed using either ` ast\parse_code() ` , which accepts a code string, or
39
39
` ast\parse_file() ` , which accepts a file path. Additionally both functions require a ` $version `
40
- argument to ensure forward-compatibility. The current version is 40 .
40
+ argument to ensure forward-compatibility. The current version is 50 .
41
41
42
42
``` php
43
- $ast = ast\parse_code('<?php ...', $version=40 );
43
+ $ast = ast\parse_code('<?php ...', $version=50 );
44
44
// or
45
- $ast = ast\parse_file('file.php', $version=40 );
45
+ $ast = ast\parse_file('file.php', $version=50 );
46
46
```
47
47
48
48
The abstract syntax tree returned by these functions consists of ` ast\Node ` objects.
@@ -72,8 +72,8 @@ The `children` property contains an array of child-nodes. These children can be
72
72
` ast\Node ` objects or plain values. The meaning of the children is node-specific and should be
73
73
deduced from context or by looking at the [ parser definition] [ parser ] .
74
74
75
- Function and class declarations use ` ast\Node\Decl ` objects instead, which specify a number of
76
- additional properties:
75
+ Prior to AST version 50, function and class declarations used ` ast\Node\Decl ` objects instead,
76
+ which specify a number of additional properties:
77
77
78
78
``` php
79
79
namespace ast\Node;
@@ -86,9 +86,9 @@ class Decl extends Node {
86
86
}
87
87
```
88
88
89
- ` endLineno ` provides the end line number of the declaration, ` name ` contains the name of the
90
- function or class (can be ` null ` for anonymous classes) and ` docComment ` contains the preceding
91
- doc comment or ` null ` if no doc comment was used .
89
+ As of AST version 50, ` ast\Node\Decl ` objects are no longer used. Instead the ` name ` and the
90
+ ` docComment ` will be provided as ordinary child nodes. The ` endLineno ` is provided as an
91
+ (undeclared, dynamic) property on the node .
92
92
93
93
Simple usage example:
94
94
@@ -100,7 +100,7 @@ $code = <<<'EOC'
100
100
$var = 42;
101
101
EOC;
102
102
103
- var_dump(ast\parse_code($code, $version=40 ));
103
+ var_dump(ast\parse_code($code, $version=50 ));
104
104
105
105
// Output:
106
106
object(ast\Node)#1 (4) {
@@ -157,7 +157,7 @@ $code = <<<'EOC'
157
157
$var = 42;
158
158
EOC;
159
159
160
- echo ast_dump(ast\parse_code($code, $version=40 )), "\n";
160
+ echo ast_dump(ast\parse_code($code, $version=50 )), "\n";
161
161
162
162
// Output:
163
163
AST_STMT_LIST
@@ -433,7 +433,9 @@ ZEND_AST_USE
433
433
Version changelog
434
434
-----------------
435
435
436
- ### 50 (in development)
436
+ ### 50 (current)
437
+
438
+ Supported since 2017-07-19.
437
439
438
440
* ` ast\Node\Decl ` nodes are no longer generated. AST kinds ` AST_FUNCTION ` , ` AST_METHOD ` ,
439
441
` AST_CLOSURE ` and ` AST_CLASS ` now also use the normal ` ast\Node ` class. The ` name ` and
@@ -447,14 +449,16 @@ Version changelog
447
449
* ` \ast\parse_file ` will now consistently return an empty statement list (similar to
448
450
` \ast\parse_code ` ) if it is was passed a zero-byte file. Previously, it would return ` null ` .
449
451
450
- ### 45 (in development)
452
+ ### 45 (supported)
453
+
454
+ Supported since 2017-07-19.
451
455
452
456
This version normalizes the AST to PHP 7.2 format.
453
457
454
458
* An ` object ` type annotation now returns an ` AST_TYPE ` with ` TYPE_OBJECT ` flag, rather than
455
459
treating ` object ` as a class name.
456
460
457
- ### 40 (current )
461
+ ### 40 (supported )
458
462
459
463
Supported since 2017-01-18.
460
464
0 commit comments