ast pecl.php.net Extension exposing PHP 7 abstract syntax tree php-ast exports the AST internally used by PHP 7. php-ast is significantly faster than PHP-Parser, because the AST construction is implemented in C. However, php-ast may only parse code that is syntactically valid on the version of PHP it runs on. Nikita Popov nikic nikic@php.net yes Tyson Andre tandre tandre@php.net yes 2024-08-10 1.1.3dev 1.1.3dev stable stable BSD-3-Clause - TBD 7.2.0 1.10.0 ast 2024-08-10 1.1.2 1.1.2 stable stable BSD-3-Clause - Fix compilation errors in PHP 8.4. - In version 110, `AST_PARAM` and `AST_PROP_ELEM` nodes have a `hooks` node for property hooks (https://wiki.php.net/rfc/property-hooks) - In version 110, `AST_CLOSURE` and `AST_ARROW_FUNC` nodes have no `name`. 2023-11-12 1.1.1 1.1.1 stable stable BSD-3-Clause - Added support for PHP 8.3 - In version 100, `AST_CLASS_CONST_GROUP` nodes have a `type` child node to represent typed class constants. 2022-08-09 1.1.0 1.1.0 stable stable BSD-3-Clause - Change documentation files to properly namespace attributes as `#[\AllowDynamicProperties]`. The reflection attributes are already correct. - Deprecated AST versions 50 and 60. - Drop support for php <= 7.1 - Fix test failures seen in php 8.2.0beta2 due to change to var_export's output format. - Add support for php 8.2 readonly classes. Add `ast\flags\CLASS_READONLY` constant. - Add support for php 8.2 `true` type. Add `ast\flags\TYPE_TRUE` constant. - Fix bug in php 8.2 where ZEND_AST_ARROW_FUNC output did not include the stub `AST_RETURN` node that was included in php 8.1 and below. 2021-11-27 1.0.16 1.0.16 stable stable BSD-3-Clause - Optimize instantiating properties of ast\Node and ast\Metadata. - Document that ast\Node implements `#[AllowDynamicProperties]` in php 8.2 - Allow ast\Node to have dynamic properties without emitting a notice in PHP 8.2. 2021-11-27 1.0.15 1.0.15 stable stable BSD-3-Clause - Allow ast\Node to have dynamic properties without emitting a notice in PHP 8.2. 2021-07-24 1.0.14 1.0.14 stable stable BSD-3-Clause - Support php 8.1 readonly properties with the flag 'MODIFIER_READONLY' - Support php 8.1 first-class callable syntax, add the node kind 'AST_CALLABLE_CONVERT' - Change the current AST version from 80 to the new version 90. AST version 85 is no longer experimental. 2021-07-08 1.0.13 1.0.13 stable stable BSD-3-Clause - Indicate in metadata that 'AST_CLASS_CONST_GROUP' and 'AST_CLASS_CONST_DECL' can have 'MODIFIER_FINAL' (and any modifier a class element can have, to reflect what the parser can actually parse) - Support php 8.1 intersection types, add the node kind 'AST_TYPE_INTERSECTION' 2021-05-16 1.0.12 1.0.12 stable stable BSD-3-Clause - Support parsing 'docComment' on php 8.1 enum cases - Indicate in metadata that 'AST_CLASS_CONST_GROUP' and 'AST_CLASS_CONST_DECL' can have MODIFIER_FINAL 2021-04-20 1.0.11 1.0.11 stable stable BSD-3-Clause - Add the experimental AST version 85. - Support php 8.1 enums, add 'type' (for enum type) to AST_CLASS nodes in AST version 85+. - Support php 8.1 'never' return type. 2020-09-12 1.0.10 1.0.10 stable stable BSD-3-Clause - Support attributes syntax change (`#[...]`) in php 8.0.0RC1. - Change the current AST version from 70 to 80. AST version 80 is no longer experimental. - Add `ReflectionParameter` defaults for `ast\parse_code` and `ast\get_supported_versions` in php 8. - Add parameter types and return types to reflection for various global functions. php-ast was already throwing a `TypeError` when invalid parameter types were received. - Always throw instead of warning when invalid parameters are passed to the ast\Node constructor. 2020-09-02 1.0.9 1.0.9 stable stable BSD-3-Clause - Support API change in php 8.0.0beta3. 2020-08-04 1.0.8 1.0.8 stable stable BSD-3-Clause - Recommend using the new constant `ast\flags\PARAM_MODIFIER_*` when checking if parameters use constructor property promotion. The values of `ast\flags\MODIFIER_*` and `ast\flags\PARAM_VARIADIC` had some overlap in some php 7 versions. The new constants will have the same values as `ast\flags\MODIFIER_*` in PHP 8.0+, but different values in PHP 7 (and these flags will never be set in php 7). - Support PHP 8.0's named arguments. - Support PHP 8.0's nullsafe operator (`?->`). 2020-07-11 1.0.7 1.0.7 stable stable BSD-3-Clause - Add the experimental AST version 80 - In AST version 80, support returning `mixed` types as an `AST_TYPE` with type `TYPE_MIXED` instead of an `AST_NAME`. - In AST version 80, support PHP 8.0 attributes for declarations. - Support PHP 8.0's Match expressions. - Support PHP 8.0 constructor property promotion, and allow indicating visibility on AST nodes. Note that `MODIFIER_PUBLIC` and `ast\AST_PARAM` modifiers had overlap in php 7.4, so the `MODIFIER_*` modifiers are only included in the provided metadata for php 8.0+ 2020-02-22 1.0.6 1.0.6 stable stable BSD-3-Clause - Support TYPE_STATIC for the php 8.0 static return type. 2019-11-23 1.0.5 1.0.5 stable stable BSD-3-Clause - Add ast\flags\TYPE_FALSE to support PHP 8.0 Union Types. 2019-11-10 1.0.4 1.0.4 stable stable BSD-3-Clause - Add AST_TYPE_UNION to support PHP 8.0 Union Types. 2019-07-27 1.0.3 1.0.3 stable stable BSD-3-Clause - Fix build error in php 7.4.0alpha3. - Add `DIM_ALTERNATIVE_SYNTAX` as a flag of `AST_DIM` for `$x{'offset'}` (for php 7.4+) - Add `PARENTHESIZED_CONDITIONAL` as a flag of `AST_CONDITIONAL` for `($a ? $b : $c)` (for php 7.4+) - Bugfix: Make `ast\kind_uses_flags(ast\AST_ARROW_FUNC)` true in php 7.3 and lower. 2019-06-30 1.0.2 1.0.2 stable stable BSD-3-Clause - Fix compatibility with (currently) PHP 7.4 and PHP 8.0. - Support AST_ARROW_FUNC for PHP 7.4. - Make $version a required parameter for `ast\parse_*`. Previously, the absence would throw a LogicException. - Make AST version 70 the current version. 2019-02-11 1.0.1 1.0.1 stable stable BSD-3-Clause - Fix compatibility with (currently) PHP 7.4 and PHP 8.0. - Support BINARY_COALESCE as a flag of AST_ASSIGN_OP for the `??=` operator added in PHP 7.4. - Add AST version 70 (experimental): - Version 70 adds AST_PROP_GROUP with type information for property groups. - Version 70 adds AST_CLASS_NAME for `Foo::class`. Previously this used AST_CLASS_CONST 2018-10-21 1.0.0 1.0.0 stable stable BSD-3-Clause This release is the same as version 0.1.7 with obsolete and deprecated functionality removed. - Removed AST versions prior to version 50. - Removed ast\Node\Decl class, which is no longer used. - Removed AST kinds AST_AND, AST_COALESCE, AST_GREATER, AST_GREATER_EQUAL, AST_OR, AST_SILENCE, AST_UNARY_MINUS, and AST_UNARY_PLUS, which are no longer used. - Removed ASSIGN_* AST flags, which are no longer used. 2018-10-06 0.1.7 0.1.7 stable stable BSD-3-Clause - Added AST version 60 with the following changes: - `AST_FUNC_DECL` and `AST_METHOD` no longer generate a `uses` child. Previously this child was always `null`. - `AST_CONST_ELEM` now always has a `docComment` child. Previously it was absent on PHP 7.0. On PHP 7.0 the value is always `null`. - Added `ARRAY_ELEM_REF` flag, which is used by `AST_ARRAY_ELEM` for by-reference array elements and (since PHP 7.3) for by-reference destructuring. Previously this flag was represented simply by the value `1`. - Deprecated AST versions 40 and 45. - Fix build against PHP 7.4-dev. 2017-10-08 0.1.6 0.1.6 stable stable BSD-3-Clause - Added ast\get_metadata() function, which returns an array of ast\Metadata objects, one for each AST kind. The metadata contains information such as the supported flags for the kind. - Added ast\get_supported_versions() function, which provides an array of currently supported AST versions. 2017-07-19 0.1.5 0.1.5 stable stable BSD-3-Clause - Fix issue #51: Make nullable array/callable have a flag of 0 in inner element, in version 40. - Added a constructor for the ast\Node class. - Added ast\flags\FUNC_GENERATOR constant, which is used since PHP 7.1. - Added ast\flags\FUNC_RETURNS_REF constant, intended to supersede ast\flags\RETURNS_REF. - Added ast\flags\CLOSURE_USE_REF constant, used by AST_CLOSURE_VAR nodes. Previously "1" was used. - Added version 45 with the following changes (PHP 7.2 support): - An `object` type annotation now returns an `AST_TYPE` with `TYPE_OBJECT` flag, rather than treating `object` as a class name. - Added version 50 with the following changes: - `ast\Node\Decl` nodes are no longer generated. AST kinds `AST_FUNCTION`, `AST_METHOD`, `AST_CLOSURE` and `AST_CLASS` now also use the normal `ast\Node` class. The `name` and `docComment` properties are now represented as children. The `endLineno` is still represented as an (undeclared) property. - An integer `__declId` has been added to declaration nodes of kind `AST_FUNCTION`, `AST_METHOD`, `AST_CLOSURE` and `AST_CLASS`. The `__declId` uniquely identifies a declaration within the parsed code and will remain the same if the code is parsed again. This is useful to distinguish closures declared on the same line, or multiple conditional declarations using the same name. The ID is not unique across different codes/files. - `\ast\parse_file` will now consistently return an empty statement list (similar to `\ast\parse_code`) if it is was passed a zero-byte file. Previously, it would return `null`. 2017-01-25 0.1.4 0.1.4 BSD-3-Clause 0.1.4 release 2017-01-18 0.1.3 0.1.3 BSD-3-Clause 0.1.3 release 2017-08-04 0.1.2 0.1.2 BSD-3-Clause 0.1.2 release 2017-12-04 0.1.1 0.1.1 BSD-3-Clause 0.1.1 release 2017-12-04 0.1.0 0.1.0 BSD-3-Clause 0.1.0 release