Skip to content
View php-ast's full-sized avatar
Block or Report

Block or report php-ast

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 100 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
php-ast/README.md

Python Get PHP-AST

PHP-AST PHP version social

Install

pip install  php-ast

exapme

# get bytes php code ast
from php_ast import php_ast
php_ast=php_ast()
php_ast.get_ast(b"<?php phpinfo();?>")
{'status': 'successed', 'ast': {'kind': 'AST_STMT_LIST', 'flags': 0, 'lineno': 1, 'children': [{'kind': 'AST_CALL', 'flags': 0, 'lineno': 1, 'children': {'expr': {'kind': 'AST_NAME', 'flags': 1, 'lineno': 1, 'children': {'name': 'phpinfo'}}, 'args': {'kind': 'AST_ARG_LIST', 'flags': 0, 'lineno': 1, 'children': []}}}]}}



# get php file ast
from php_ast import php_ast
php_ast=php_ast()
php_ast.get_file_ast("/home/11.php")
{'status': 'successed', 'ast': {'kind': 'AST_STMT_LIST', 'flags': 0, 'lineno': 1, 'children': [{'kind': 'AST_CALL', 'flags': 0, 'lineno': 1, 'children': {'expr': {'kind': 'AST_NAME', 'flags': 1, 'lineno': 1, 'children': {'name': 'phpinfo'}}, 'args': {'kind': 'AST_ARG_LIST', 'flags': 0, 'lineno': 1, 'children': []}}}]}}

说明

  • 本项目是基于php-ast扩展的python模块,用于获取php代码的ast树
  • 暂时只支持Linux 系统

参考:

Popular repositories

  1. php-ast php-ast Public

    Parsing PHP source code using Python and generating ASTs

    C 4