{"id":13700078,"url":"https://github.com/nikic/php-ast","last_synced_at":"2025-05-16T06:06:36.202Z","repository":{"id":20492725,"uuid":"23770986","full_name":"nikic/php-ast","owner":"nikic","description":"Extension exposing PHP 7 abstract syntax tree","archived":false,"fork":false,"pushed_at":"2024-08-10T18:38:40.000Z","size":637,"stargazers_count":949,"open_issues_count":9,"forks_count":78,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-04-08T16:01:50.556Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nikic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-07T21:04:40.000Z","updated_at":"2025-03-22T23:50:17.000Z","dependencies_parsed_at":"2024-06-19T02:56:24.863Z","dependency_job_id":"d39066ec-67be-4d56-aa4d-6832e8b7ea79","html_url":"https://github.com/nikic/php-ast","commit_stats":{"total_commits":326,"total_committers":21,"mean_commits":"15.523809523809524","dds":0.6748466257668712,"last_synced_commit":"66b258d1c0144307473e5c042be025be9b134e5e"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikic%2Fphp-ast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikic%2Fphp-ast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikic%2Fphp-ast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikic%2Fphp-ast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikic","download_url":"https://codeload.github.com/nikic/php-ast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478190,"owners_count":22077676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T20:00:48.226Z","updated_at":"2025-05-16T06:06:31.193Z","avatar_url":"https://github.com/nikic.png","language":"PHP","funding_links":[],"categories":["代码分析"],"sub_categories":[],"readme":"php-ast\n=======\n\nThis extension exposes the abstract syntax tree generated by PHP 7 and 8.\n\n**This is the documentation for version 1.x.y. See also [documentation for version 0.1.x][v0_1_x].**\n\nTable of Contents\n-----------------\n\n * [Installation](#installation)\n * [API overview](#api-overview)\n * [Basic usage](#basic-usage)\n * [Example](#example)\n * [Metadata](#metadata)\n * [Flags](#flags)\n * [AST node kinds](#ast-node-kinds)\n * [AST versioning](#ast-versioning)\n * [Differences to PHP-Parser](#differences-to-php-parser)\n\nInstallation\n------------\n\n**Windows**: Download a [prebuilt Windows DLL](https://downloads.php.net/~windows/pecl/releases/ast/)\nand move it into the `ext/` directory of your PHP installation. Furthermore, add\n`extension=php_ast.dll` to your `php.ini` file.\n(The [php-ast PECL page](https://downloads.php.net/~windows/pecl/releases/ast/) also links to the same DLLs for Windows.)\n\n**Unix (PECL)**: Run `pecl install ast` and add `extension=ast.so` to your `php.ini`.\n\n**Unix (Compile)**: Compile and install the extension as follows.\n\n```sh\nphpize\n./configure\nmake\nsudo make install\n```\n\nAdditionally add `extension=ast.so` to your `php.ini` file.\n\nAPI overview\n------------\n\nDefines:\n\n * `ast\\Node` class\n * `ast\\Metadata` class\n * `ast\\AST_*` kind constants\n * `ast\\flags\\*` flag constants\n * `ast\\parse_file(string $filename, int $version)`\n * `ast\\parse_code(string $code, int $version [, string $filename = \"string code\"])`\n * `ast\\get_kind_name(int $kind)`\n * `ast\\kind_uses_flags(int $kind)`\n * `ast\\get_metadata()`\n * `ast\\get_supported_versions(bool $exclude_deprecated = false)`\n\nBasic usage\n-----------\n\nCode can be parsed using either `ast\\parse_code()`, which accepts a code string, or\n`ast\\parse_file()`, which accepts a file path. Additionally, both functions require a `$version`\nargument to ensure forward-compatibility. The current version is 110.\n\n```php\n$ast = ast\\parse_code('\u003c?php ...', $version=100);\n// or\n$ast = ast\\parse_file('file.php', $version=100);\n```\n\nThe abstract syntax tree returned by these functions consists of `ast\\Node` objects.\n`ast\\Node` is declared as follows:\n\n```php\nnamespace ast;\nclass Node {\n    public $kind;\n    public $flags;\n    public $lineno;\n    public $children;\n}\n```\n\nThe `kind` property specifies the type of the node. It is an integral value, which corresponds to\none of the `ast\\AST_*` constants, for example `ast\\AST_STMT_LIST`. See the\n[AST node kinds section](#ast-node-kinds) for an overview of the available node kinds.\n\nThe `flags` property contains node specific flags. It is always defined, but for most nodes it is\nalways zero. See the [flags section](#flags) for a list of flags supported by the different node\nkinds.\n\nThe `lineno` property specifies the *starting* line number of the node.\n\nThe `children` property contains an array of child-nodes. These children can be either other\n`ast\\Node` objects or plain values. There are two general categories of nodes: Normal AST nodes,\nwhich have a fixed set of named child nodes, as well as list nodes, which have a variable number\nof children. The [AST node kinds section](#ast-node-kinds) contains a list of the child names for\nthe different node kinds.\n\nExample\n-------\n\nSimple usage example:\n\n```php\n\u003c?php\n\n$code = \u003c\u003c\u003c'EOC'\n\u003c?php\n$var = 42;\nEOC;\n\nvar_dump(ast\\parse_code($code, $version=70));\n\n// Output:\nobject(ast\\Node)#1 (4) {\n  [\"kind\"]=\u003e\n  int(132)\n  [\"flags\"]=\u003e\n  int(0)\n  [\"lineno\"]=\u003e\n  int(1)\n  [\"children\"]=\u003e\n  array(1) {\n    [0]=\u003e\n    object(ast\\Node)#2 (4) {\n      [\"kind\"]=\u003e\n      int(517)\n      [\"flags\"]=\u003e\n      int(0)\n      [\"lineno\"]=\u003e\n      int(2)\n      [\"children\"]=\u003e\n      array(2) {\n        [\"var\"]=\u003e\n        object(ast\\Node)#3 (4) {\n          [\"kind\"]=\u003e\n          int(256)\n          [\"flags\"]=\u003e\n          int(0)\n          [\"lineno\"]=\u003e\n          int(2)\n          [\"children\"]=\u003e\n          array(1) {\n            [\"name\"]=\u003e\n            string(3) \"var\"\n          }\n        }\n        [\"expr\"]=\u003e\n        int(42)\n      }\n    }\n  }\n}\n```\n\nThe [`util.php`][util] file defines an `ast_dump()` function, which can be used to create a more\ncompact and human-readable dump of the AST structure:\n\n```php\n\u003c?php\n\nrequire 'path/to/util.php';\n\n$code = \u003c\u003c\u003c'EOC'\n\u003c?php\n$var = 42;\nEOC;\n\necho ast_dump(ast\\parse_code($code, $version=70)), \"\\n\";\n\n// Output:\nAST_STMT_LIST\n    0: AST_ASSIGN\n        var: AST_VAR\n            name: \"var\"\n        expr: 42\n```\n\nTo additionally show line numbers pass the `AST_DUMP_LINENOS` option as the second argument to\n`ast_dump()`.\n\nA more substantial AST dump can be found [in the tests][test_dump].\n\nMetadata\n--------\n\nThere are a number of functions which provide meta-information for the AST structure:\n\n`ast\\get_kind_name()` returns a string name for an integral node kind.\n\n`ast\\kind_uses_flags()` determines whether the `flags` of a node kind may ever be non-zero.\n\n`ast\\get_metadata()` returns metadata about all AST node kinds. The return value is a map from AST\nnode kinds to `ast\\Metadata` objects defined as follows.\n\n```php\nnamespace ast;\nclass Metadata\n{\n    public $kind;\n    public $name;\n    public $flags;\n    public $flagsCombinable;\n}\n```\n\nThe `kind` is the integral node kind, while `name` is the same name as returned by the\n`get_kind_name()` function.\n\n`flags` is an array of flag constant names, which may be used by the node kind. `flagsCombinable`\nspecifies whether the flag should be checked using `===` (not combinable) or using `\u0026` (combinable).\nTogether these two values provide programmatic access to the information listed in the\n[flags section](#flags).\n\nThe AST metadata is intended for use in tooling for working the AST, such as AST dumpers.\n\nFlags\n-----\n\nThis section lists which flags are used by which AST node kinds. The \"combinable\" flags can be\ncombined using bitwise or and should be checked by using `$ast-\u003eflags \u0026 ast\\flags\\FOO`. The\n\"exclusive\" flags are used standalone and should be checked using `$ast-\u003eflags === ast\\flags\\BAR`.\n\n```\n// Used by ast\\AST_NAME (exclusive)\nast\\flags\\NAME_FQ (= 0)    // example: \\Foo\\Bar\nast\\flags\\NAME_NOT_FQ      // example: Foo\\Bar\nast\\flags\\NAME_RELATIVE    // example: namespace\\Foo\\Bar\n\n// Used by ast\\AST_METHOD, ast\\AST_PROP_DECL, ast\\AST_PROP_GROUP,\n// ast\\AST_CLASS_CONST_DECL, ast\\AST_CLASS_CONST_GROUP, and ast\\AST_TRAIT_ALIAS (combinable)\nast\\flags\\MODIFIER_PUBLIC\nast\\flags\\MODIFIER_PROTECTED\nast\\flags\\MODIFIER_PRIVATE\nast\\flags\\MODIFIER_STATIC\nast\\flags\\MODIFIER_ABSTRACT\nast\\flags\\MODIFIER_FINAL\nast\\flags\\MODIFIER_READONLY\n\n// Used by ast\\AST_CLOSURE, ast\\AST_ARROW_FUNC (combinable)\nast\\flags\\MODIFIER_STATIC\n\n// Used by ast\\AST_FUNC_DECL, ast\\AST_METHOD, ast\\AST_CLOSURE, ast\\AST_ARROW_FUNC (combinable)\nast\\flags\\FUNC_RETURNS_REF  // legacy alias: ast\\flags\\RETURNS_REF\nast\\flags\\FUNC_GENERATOR    // used only in PHP \u003e= 7.1\n\n// Used by ast\\AST_CLOSURE_VAR\nast\\flags\\CLOSURE_USE_REF\n\n// Used by ast\\AST_CLASS (combinable since PHP 8.1 enums)\nast\\flags\\CLASS_ABSTRACT\nast\\flags\\CLASS_FINAL\nast\\flags\\CLASS_TRAIT\nast\\flags\\CLASS_INTERFACE\nast\\flags\\CLASS_ANONYMOUS\nast\\flags\\CLASS_ENUM      // php 8.1 enums\nast\\flags\\CLASS_READONLY  // php 8.2 readonly classes\n\n// Used by ast\\AST_PARAM (combinable)\nast\\flags\\PARAM_REF\nast\\flags\\PARAM_VARIADIC\nast\\flags\\PARAM_MODIFIER_PUBLIC (available since 1.0.8, same as ast\\flags\\MODIFIER_* in PHP \u003e= 8.0)\nast\\flags\\PARAM_MODIFIER_PROTECTED (available since 1.0.8)\nast\\flags\\PARAM_MODIFIER_PRIVATE (available since 1.0.8)\n\n// Used by ast\\AST_TYPE (exclusive)\nast\\flags\\TYPE_ARRAY\nast\\flags\\TYPE_CALLABLE\nast\\flags\\TYPE_VOID\nast\\flags\\TYPE_BOOL\nast\\flags\\TYPE_LONG\nast\\flags\\TYPE_DOUBLE\nast\\flags\\TYPE_STRING\nast\\flags\\TYPE_ITERABLE\nast\\flags\\TYPE_OBJECT\nast\\flags\\TYPE_NULL    // php 8.0 union types\nast\\flags\\TYPE_FALSE   // php 8.0 union types\nast\\flags\\TYPE_TRUE    // php 8.2 true type\nast\\flags\\TYPE_STATIC  // php 8.0 static return type\nast\\flags\\TYPE_MIXED   // php 8.0 mixed type\nast\\flags\\TYPE_NEVER   // php 8.1 never type\n\n// Used by ast\\AST_CAST (exclusive)\nast\\flags\\TYPE_NULL\nast\\flags\\TYPE_BOOL\nast\\flags\\TYPE_LONG\nast\\flags\\TYPE_DOUBLE\nast\\flags\\TYPE_STRING\nast\\flags\\TYPE_ARRAY\nast\\flags\\TYPE_OBJECT\n\n// Used by ast\\AST_UNARY_OP (exclusive)\nast\\flags\\UNARY_BOOL_NOT\nast\\flags\\UNARY_BITWISE_NOT\nast\\flags\\UNARY_MINUS\nast\\flags\\UNARY_PLUS\nast\\flags\\UNARY_SILENCE\n\n// Used by ast\\AST_BINARY_OP and ast\\AST_ASSIGN_OP (exclusive)\nast\\flags\\BINARY_BITWISE_OR\nast\\flags\\BINARY_BITWISE_AND\nast\\flags\\BINARY_BITWISE_XOR\nast\\flags\\BINARY_CONCAT\nast\\flags\\BINARY_ADD\nast\\flags\\BINARY_SUB\nast\\flags\\BINARY_MUL\nast\\flags\\BINARY_DIV\nast\\flags\\BINARY_MOD\nast\\flags\\BINARY_POW\nast\\flags\\BINARY_SHIFT_LEFT\nast\\flags\\BINARY_SHIFT_RIGHT\nast\\flags\\BINARY_COALESCE\n\n// Used by ast\\AST_BINARY_OP (exclusive)\nast\\flags\\BINARY_BOOL_AND\nast\\flags\\BINARY_BOOL_OR\nast\\flags\\BINARY_BOOL_XOR\nast\\flags\\BINARY_IS_IDENTICAL\nast\\flags\\BINARY_IS_NOT_IDENTICAL\nast\\flags\\BINARY_IS_EQUAL\nast\\flags\\BINARY_IS_NOT_EQUAL\nast\\flags\\BINARY_IS_SMALLER\nast\\flags\\BINARY_IS_SMALLER_OR_EQUAL\nast\\flags\\BINARY_IS_GREATER\nast\\flags\\BINARY_IS_GREATER_OR_EQUAL\nast\\flags\\BINARY_SPACESHIP\n\n// Used by ast\\AST_MAGIC_CONST (exclusive)\nast\\flags\\MAGIC_LINE\nast\\flags\\MAGIC_FILE\nast\\flags\\MAGIC_DIR\nast\\flags\\MAGIC_NAMESPACE\nast\\flags\\MAGIC_FUNCTION\nast\\flags\\MAGIC_METHOD\nast\\flags\\MAGIC_CLASS\nast\\flags\\MAGIC_TRAIT\n\n// Used by ast\\AST_USE, ast\\AST_GROUP_USE and ast\\AST_USE_ELEM (exclusive)\nast\\flags\\USE_NORMAL\nast\\flags\\USE_FUNCTION\nast\\flags\\USE_CONST\n\n// Used by ast\\AST_INCLUDE_OR_EVAL (exclusive)\nast\\flags\\EXEC_EVAL\nast\\flags\\EXEC_INCLUDE\nast\\flags\\EXEC_INCLUDE_ONCE\nast\\flags\\EXEC_REQUIRE\nast\\flags\\EXEC_REQUIRE_ONCE\n\n// Used by ast\\AST_ARRAY (exclusive), since PHP 7.1\nast\\flags\\ARRAY_SYNTAX_SHORT\nast\\flags\\ARRAY_SYNTAX_LONG\nast\\flags\\ARRAY_SYNTAX_LIST\n\n// Used by ast\\AST_ARRAY_ELEM (exclusive)\nast\\flags\\ARRAY_ELEM_REF\n\n// Used by ast\\AST_DIM (combinable), since PHP 7.4\nast\\flags\\DIM_ALTERNATIVE_SYNTAX\nast\\flags\\ENCAPS_VAR_DOLLAR_CURLY  // php 8.2 deprecation, only available in php 8.2+\n\n// Used by ast\\AST_VAR (combinable), since PHP 8.2\nast\\flags\\ENCAPS_VAR_DOLLAR_CURLY\nast\\flags\\ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR\n\n// Used by ast\\AST_CONDITIONAL (combinable), since PHP 7.4\nast\\flags\\PARENTHESIZED_CONDITIONAL\n```\n\nAST node kinds\n--------------\n\nThis section lists the AST node kinds that are supported and the names of their child nodes.\n\n```\nAST_ARRAY_ELEM:           value, key\nAST_ARROW_FUNC:           name, docComment, params, stmts, returnType, attributes // name removed in version 110\nAST_ASSIGN:               var, expr\nAST_ASSIGN_OP:            var, expr\nAST_ASSIGN_REF:           var, expr\nAST_ATTRIBUTE:            class, args            // php 8.0+ attributes (version 80+)\nAST_BINARY_OP:            left, right\nAST_BREAK:                depth\nAST_CALL:                 expr, args\nAST_CALLABLE_CONVERT:                            // php 8.1+ first-class callable syntax\nAST_CAST:                 expr\nAST_CATCH:                class, var, stmts\nAST_CLASS:                name, docComment, extends, implements, stmts, (for enums) type\nAST_CLASS_CONST:          class, const\nAST_CLASS_CONST_GROUP     class, attributes, type // version 80+\nAST_CLASS_NAME:           class                   // version 70+\nAST_CLONE:                expr\nAST_CLOSURE:              name, docComment, params, uses, stmts, returnType, attributes // name removed in version 110\nAST_CLOSURE_VAR:          name\nAST_CONDITIONAL:          cond, true, false\nAST_CONST:                name\nAST_CONST_ELEM:           name, value, docComment\nAST_CONTINUE:             depth\nAST_DECLARE:              declares, stmts\nAST_DIM:                  expr, dim\nAST_DO_WHILE:             stmts, cond\nAST_ECHO:                 expr\nAST_EMPTY:                expr\nAST_ENUM_CASE:            name, expr, docComment, attributes // php 8.1+ enums\nAST_EXIT:                 expr\nAST_FOR:                  init, cond, loop, stmts\nAST_FOREACH:              expr, value, key, stmts\nAST_FUNC_DECL:            name, docComment, params, stmts, returnType, attributes\n                          uses                   // prior to version 60\nAST_GLOBAL:               var\nAST_GOTO:                 label\nAST_GROUP_USE:            prefix, uses\nAST_HALT_COMPILER:        offset\nAST_IF_ELEM:              cond, stmts\nAST_INCLUDE_OR_EVAL:      expr\nAST_INSTANCEOF:           expr, class\nAST_ISSET:                var\nAST_LABEL:                name\nAST_MAGIC_CONST:\nAST_MATCH:                cond, stmts            // php 8.0+ match\nAST_MATCH_ARM:            cond, expr             // php 8.0+ match\nAST_METHOD:               name, docComment, params, stmts, returnType, attributes\n                          uses                   // prior to version 60\nAST_METHOD_CALL:          expr, method, args\nAST_METHOD_REFERENCE:     class, method\nAST_NAME:                 name\nAST_NAMED_ARG:            name, expr             // php 8.0 named parameters\nAST_NAMESPACE:            name, stmts\nAST_NEW:                  class, args\nAST_NULLABLE_TYPE:        type                   // Used only since PHP 7.1\nAST_NULLSAFE_METHOD_CALL: expr, method, args     // php 8.0 null safe operator\nAST_NULLSAFE_PROP:        expr, prop             // php 8.0 null safe operator\nAST_PARAM:                type, name, default, attributes, docComment, hooks // 'hooks' field added in version 110\nAST_POST_DEC:             var\nAST_POST_INC:             var\nAST_PRE_DEC:              var\nAST_PRE_INC:              var\nAST_PRINT:                expr\nAST_PROP:                 expr, prop\nAST_PROP_ELEM:            name, default, docComment, hooks // 'hooks' field added in version 110\nAST_PROP_GROUP:           type, props, attributes // version 70+\nAST_PROPERTY_HOOK:        name, docComment, params, stmts, attributes // version 110+\nAST_PROPERTY_HOOK_SHORT_BODY: expr\nAST_REF:                  var                    // only used in foreach ($a as \u0026$v)\nAST_RETURN:               expr\nAST_SHELL_EXEC:           expr\nAST_STATIC:               var, default\nAST_STATIC_CALL:          class, method, args\nAST_STATIC_PROP:          class, prop\nAST_SWITCH:               cond, stmts\nAST_SWITCH_CASE:          cond, stmts\nAST_THROW:                expr\nAST_TRAIT_ALIAS:          method, alias\nAST_TRAIT_PRECEDENCE:     method, insteadof\nAST_TRY:                  try, catches, finally\nAST_TYPE:\nAST_UNARY_OP:             expr\nAST_UNPACK:               expr\nAST_UNSET:                var\nAST_USE_ELEM:             name, alias\nAST_USE_TRAIT:            traits, adaptations\nAST_VAR:                  name\nAST_WHILE:                cond, stmts\nAST_YIELD:                value, key\nAST_YIELD_FROM:           expr\n\n// List nodes (numerically indexed children):\nAST_ARG_LIST\nAST_ARRAY\nAST_ATTRIBUTE_LIST        // php 8.0+ attributes (version 80+)\nAST_ATTRIBUTE_GROUP       // php 8.0+ attributes (version 80+)\nAST_CATCH_LIST\nAST_CLASS_CONST_DECL\nAST_CLOSURE_USES\nAST_CONST_DECL\nAST_ENCAPS_LIST           // interpolated string: \"foo$bar\"\nAST_EXPR_LIST\nAST_IF\nAST_LIST\nAST_MATCH_ARM_LIST        // php 8.0+ match\nAST_NAME_LIST\nAST_PARAM_LIST\nAST_PROP_DECL\nAST_STMT_LIST\nAST_SWITCH_LIST\nAST_TRAIT_ADAPTATIONS\nAST_USE\nAST_TYPE_UNION            // php 8.0+ union types\nAST_TYPE_INTERSECTION     // php 8.1+ intersection types\n```\n\nAST Versioning\n--------------\n\nThe `ast\\parse_code()` and `ast\\parse_file()` functions each accept a required AST `$version`\nargument. The idea behind the AST version is that we may need to change the format of the AST to\naccount for new features in newer PHP versions, or to improve it in other ways. Such changes will\nalways be made under a new AST version, while previous formats continue to be supported for some\ntime.\n\nOld AST versions may be deprecated in minor versions and removed in major versions of the AST extension.\n\nA list of currently supported versions is available through `ast\\get_supported_versions()`. The\nfunction accepts a boolean argument that determines whether deprecated versions should be excluded.\n\nIn the following the changes in the respective AST versions, as well as their current support state,\nare listed.\n\n### 110 (current)\n\nSupported since 1.1.2 (2024-08-10).\n\n* Add a `hooks` child node for `AST_PROP_ELEM` (PHP 8.4 property hooks) and `AST_PARAM` (constructor property promotion can have property hooks)\n* Add new node kinds `AST_PROPERTY_HOOK` and `AST_PROPERTY_HOOK_SHORT_BODY`.\n* Remove the `name` child node from the `AST_ARROW_FUNC` and `AST_CLOSURE` nodes (previously `\"{closure}\"`)\n\n### 100 (stable)\n\nSupported since 1.1.1 (2023-11-12).\n\n* Add a `type` child node for all `AST_CLASS_CONST_GROUP` nodes.\n\n### 90 (stable)\n\nSupported since 1.0.14 (2021-07-24)\n\n* Same as AST version 85.\n\n### 85 (stable)\n\nSupported since 1.0.11 (2021-04-20)\n\n* Add a `type` child node (for enum type) for all `AST_CLASS` nodes.\n\n### 80 (stable)\n\nSupported since 1.0.10 (2020-09-12).\n\n* `mixed` type hints are now reported as an `AST_TYPE` with type `TYPE_MIXED` instead of an `AST_NAME`.\n* `AST_CLASS_CONST_GROUP` nodes are emitted for class constant declarations wrapping the `AST_CLASS_CONST_DECL` and any attributes.\n  Previously, `AST_CLASS_CONST_DECL` would be emitted.\n* `AST_PARAM`, `AST_CLASS_DECL`, `AST_METHOD`, `AST_PROP_DECL`, `AST_CLOSURE`, `AST_FUNC_DECL`, and `AST_ARROW_FUNC` nodes\n  now contain an attributes child.\n\n### 70 (stable)\n\nSupported since 1.0.1 (2019-02-11).\n\n* `AST_PROP_GROUP` was added to support PHP 7.4's typed properties.\n  The property visibility modifiers are now part of `AST_PROP_GROUP` instead of `AST_PROP_DECL`.\n\n  Note that property group type information is only available with AST versions 70+.\n* `AST_CLASS_NAME` is created instead of `AST_CLASS_CONST` for `SomeClass::class`.\n\n### 60 (deprecated)\n\nSupported since 0.1.7 (2018-10-06).\nDeprecated in php-ast 1.1.0.\n\n* `AST_FUNC_DECL` and `AST_METHOD` no longer generate a `uses` child. Previously this child was\n  always `null`.\n* `AST_CONST_ELEM` now always has a `docComment` child. Previously it was absent on PHP 7.0.\n  On PHP 7.0 the value is always `null`.\n\n### 50 (deprecated)\n\nSupported since 0.1.5 (2017-07-19).\nDeprecated in php-ast 1.1.0.\n\nThis is the oldest AST version available in 1.0.0. See the\n[0.1.x AST version changelog][v0_1_x_versions] for information on changes prior to this version.\n\nDifferences to PHP-Parser\n-------------------------\n\nNext to php-ast I also maintain the [PHP-Parser][php-parser] library, which has some overlap with\nthis extension. This section summarizes the main differences between php-ast and PHP-Parser so you\nmay decide which is preferable for your use-case.\n\nThe primary difference is that php-ast is a PHP extension (written in C) which exports the AST\ninternally used by PHP 7 and 8. PHP-Parser on the other hand is library written in PHP. This has a number\nof consequences:\n\n * php-ast is significantly faster than PHP-Parser, because the AST construction is implemented in\n   C.\n * php-ast needs to be installed as an extension, on Linux either by compiling it manually or\n   retrieving it from a package manager, on Windows by loading a DLL. PHP-Parser is installed as a\n   Composer dependency.\n * php-ast only runs on PHP \u003e= 7.0 (php-ast 1.0.16 was the last version supporting php \u003c= 7.1), as prior versions did not use an internal AST. PHP-Parser\n   supports PHP \u003e= 5.5.\n * php-ast may only parse code that is syntactically valid on the version of PHP it runs on. This\n   means that it's not possible to parse code using features of newer versions (e.g. PHP 7.4 code\n   while running on PHP 7.2). Similarly, it is not possible to parse code that is no longer\n   syntactically valid on the used version (e.g. some PHP 5 code may no longer be parsed -- however\n   most code will work). PHP-Parser supports parsing both newer and older (up to PHP 5.2) versions.\n * php-ast can only parse code which is syntactically valid, while PHP-Parser can provide a partial\n   AST for code that contains errors (e.g., because it is currently being edited).\n * php-ast only provides the starting line number (and for declarations the ending line number) of\n   nodes, because this is the only part that PHP itself stores. PHP-Parser provides precise file\n   offsets.\n\nThere are a number of differences in the AST representation and available support code:\n\n * The PHP-Parser library uses a separate class for every node type, with child nodes stored as\n   type-annotated properties. php-ast uses one class for everything, with children stored as\n   arrays. The former approach is friendlier to developers because it has very good IDE integration.\n   The php-ast extension does not use separate classes, because registering hundreds of classes was\n   judged a no-go for a bundled extension.\n * The PHP-Parser library contains various support code for working with the AST, while php-ast only\n   handles AST construction. The reason for this is that implementing this support code in C is\n   extremely complicated and there is little other benefit to implementing it in C. The main\n   components that PHP-Parser offers that may be of interest are:\n    * Node dumper (human readable representation): While the php-ast extension does not directly\n      implement this, a `ast_dump` function is provided in the `util.php` file.\n    * Pretty printer (converting the AST back to PHP code): This is not provided natively, but the\n      [php-ast-reverter][php-ast-reverter] package implements this functionality.\n    * Name resolution (resolving namespace prefixes and aliases): There is currently no standalone\n      package for this.\n    * AST traversal / visitation: There is currently no standalone package for this either, but\n      implementing a recursive AST walk is easy.\n\nThe [tolerant-php-parser-to-php-ast][tolerant-php-parser-to-php-ast] project can convert the AST produced by\n[tolerant-php-parser][tolerant-php-parser] (Another pure PHP parser library) into the format used by the php-ast extension.\nThis can be used as a slow fallback in\ncase the php-ast extension is not available. It may also be used to produce a partial php-ast output\nfor code with syntax errors.\n\n  [parser]: http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_language_parser.y\n  [util]: https://github.com/nikic/php-ast/blob/master/util.php\n  [test_dump]: https://github.com/nikic/php-ast/blob/master/tests/001.phpt\n  [php-parser]: https://github.com/nikic/PHP-Parser\n  [php-ast-reverter]: https://github.com/tpunt/php-ast-reverter\n  [tolerant-php-parser]: https://github.com/Microsoft/tolerant-php-parser\n  [tolerant-php-parser-to-php-ast]: https://github.com/tysonandre/tolerant-php-parser-to-php-ast\n  [v0_1_x]: https://github.com/nikic/php-ast/tree/v0.1.x#php-ast\n  [v0_1_x_versions]: https://github.com/nikic/php-ast/tree/v0.1.x#ast-versioning\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikic%2Fphp-ast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikic%2Fphp-ast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikic%2Fphp-ast/lists"}