{"id":13694412,"url":"https://github.com/z7zmey/php-parser","last_synced_at":"2025-07-12T22:03:06.715Z","repository":{"id":44679857,"uuid":"109795136","full_name":"z7zmey/php-parser","owner":"z7zmey","description":"PHP parser written in Go","archived":false,"fork":false,"pushed_at":"2021-04-28T03:22:19.000Z","size":12648,"stargazers_count":938,"open_issues_count":18,"forks_count":63,"subscribers_count":31,"default_branch":"master","last_synced_at":"2024-09-30T09:06:33.557Z","etag":null,"topics":["ast","go","parser","php"],"latest_commit_sha":null,"homepage":"https://php-parser.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/z7zmey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-07T06:20:46.000Z","updated_at":"2024-09-30T01:40:37.000Z","dependencies_parsed_at":"2022-09-26T22:11:35.796Z","dependency_job_id":null,"html_url":"https://github.com/z7zmey/php-parser","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z7zmey%2Fphp-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z7zmey%2Fphp-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z7zmey%2Fphp-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z7zmey%2Fphp-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/z7zmey","download_url":"https://codeload.github.com/z7zmey/php-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224346573,"owners_count":17296242,"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":["ast","go","parser","php"],"created_at":"2024-08-02T17:01:31.385Z","updated_at":"2024-11-12T20:32:15.181Z","avatar_url":"https://github.com/z7zmey.png","language":"Go","readme":"PHP Parser written in Go\n========================\n\n\u003cimg src=\"./parser.jpg\" alt=\"PHP Parser written in Go\" width=\"980\"/\u003e\n\n[![GoDoc](https://godoc.org/github.com/z7zmey/php-parser?status.svg)](https://godoc.org/github.com/z7zmey/php-parser)\n[![Build Status](https://travis-ci.org/z7zmey/php-parser.svg?branch=master)](https://travis-ci.org/z7zmey/php-parser)\n[![Go Report Card](https://goreportcard.com/badge/github.com/z7zmey/php-parser)](https://goreportcard.com/report/github.com/z7zmey/php-parser)\n[![Maintainability](https://api.codeclimate.com/v1/badges/950783b2e739db26e0ed/maintainability)](https://codeclimate.com/github/z7zmey/php-parser/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/950783b2e739db26e0ed/test_coverage)](https://codeclimate.com/github/z7zmey/php-parser/test_coverage)\n\nThis project uses [goyacc](https://godoc.org/golang.org/x/tools/cmd/goyacc) and [ragel](https://www.colm.net/open-source/ragel/) tools to create PHP parser. It parses source code into [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree). It can be used to write static analysis, refactoring, metrics, code style formatting tools.\n\n#### Try it online: [demo](https://php-parser.com)\n\nFeatures:\n---------\n\n- Fully support PHP 5 and PHP 7 syntax\n- Abstract syntax tree (AST) representation\n- Traversing AST\n- Resolving namespaced names\n- Parsing syntax-invalid PHP files\n- Saving and printing free-floating comments and whitespaces\n\nWho Uses\n--------\n\n[VKCOM/noverify](https://github.com/VKCOM/noverify) - NoVerify is a pretty fast linter for PHP\n\n[quasilyte/phpgrep](https://github.com/quasilyte/phpgrep) - phpgrep is a tool for syntax-aware PHP code search\n\nUsage example\n-------\n\n```Golang\npackage main\n\nimport (\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/z7zmey/php-parser/pkg/cfg\"\n\t\"github.com/z7zmey/php-parser/pkg/errors\"\n\t\"github.com/z7zmey/php-parser/pkg/parser\"\n\t\"github.com/z7zmey/php-parser/pkg/version\"\n\t\"github.com/z7zmey/php-parser/pkg/visitor/dumper\"\n)\n\nfunc main() {\n\tsrc := []byte(`\u003c? echo \"Hello world\";`)\n\n\t// Error handler\n\n\tvar parserErrors []*errors.Error\n\terrorHandler := func(e *errors.Error) {\n\t\tparserErrors = append(parserErrors, e)\n\t}\n\n\t// Parse\n\n\trootNode, err := parser.Parse(src, cfg.Config{\n\t\tVersion:          \u0026version.Version{Major: 5, Minor: 6},\n\t\tErrorHandlerFunc: errorHandler,\n\t})\n\n\tif err != nil {\n\t\tlog.Fatal(\"Error:\" + err.Error())\n\t}\n\n\t// Dump\n\n\tgoDumper := dumper.NewDumper(os.Stdout).\n\t\tWithTokens().\n\t\tWithPositions()\n\n\trootNode.Accept(goDumper)\n}\n```\n\nRoadmap\n-------\n\n- Control Flow Graph (CFG)\n- PHP8\n\nInstall\n-------\n\n```\ngo get github.com/z7zmey/php-parser/cmd/php-parser\n```\n\nCLI\n---\n\n```\nphp-parser [flags] \u003cpath\u003e ...\n```\n\n| flag    | type   | description                       |\n| ------- | ------ | --------------------------------- |\n| -p      | bool   | print filepath                    |\n| -e      | bool   | print errors                      |\n| -d      | bool   | dump in golang format             |\n| -r      | bool   | resolve names                     |\n| -prof   | string | start profiler: [cpu, mem, trace] |\n| -phpver | string | php version (default: 7.4)        |\n\nNamespace resolver\n------------------\n\nNamespace resolver is a visitor that resolves nodes fully qualified name and saves into `map[node.Node]string` structure\n\n- For `Class`, `Interface`, `Trait`, `Function`, `Constant` nodes it saves name with current namespace.\n- For `Name`, `Relative`, `FullyQualified` nodes it resolves `use` aliases and saves a fully qualified name.\n","funding_links":[],"categories":["开源类库","Code Analysis","Open source library","Go","代码分析","相关工具","Repositories","Libraries for creating HTTP middlewares","相关工具`go相关工具和插件`"],"sub_categories":["解释器","Routers","Interpreter","路由器","代码分析"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz7zmey%2Fphp-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fz7zmey%2Fphp-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz7zmey%2Fphp-parser/lists"}