|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72559 Function to returns the PHP AST
Submitted: 2016-07-07 21:30 UTC Modified: 2016-07-13 01:44 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: david dot proweb at gmail dot com Assigned:
Status: Verified Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: david dot proweb at gmail dot com
New email:
PHP Version: OS:


 [2016-07-07 21:30 UTC] david dot proweb at gmail dot com
Currently, PHP have a function that returns the TOKENs of language (token_get_all), but if you wants to read AST, you should use some package like nikic/php-parser, and it have some specific problems:

1. It's slower than PHP AST because it reprocess code and implements it own lexer;
2. It should be updated together of PHP (currently not is a great problem because is very active);

It should be done by own PHP, because it have all process that allows does that (I guess). Basically need some code to allow read it by code.

But need some considerations:

It should not implements a lot of classes, onde for each AST key. It should send raw parameters data to a processor that will decides how it will be parsed. Basically, I think that a raw array can solve that.


    echo "Hello", "World";
    Hello\World('Foo', 'Bar' . 'Baz');


Note: simple values can stays as literals, array should specify the object key type (maybe the biggest problem).

        'key' => 'echo',
        'exprs' => [
        'key' => 'functionCall',
        'name' => [
        'args' => [
                'key' => 'concatenate',
                'values' => 

And some limitations:

It'll be PHP version dependent, it is, if I try to parse a 4.x PHP code it'll be impossible because of the PHP 7.1 code compatibility, in this case, the package can work on a polyfill. In same circunstancies, could be impossible, on PHP 7.1, parses a code fom PHP 7.2, so, polyfills too can solve that;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-07 21:37 UTC]
-Package: PHP Language Specification +Package: *General Issues
 [2016-07-08 06:15 UTC]
@nikic has an "experimental" extension for this <> and there's a draft RFC about getting it (or some derivative version of it, or something like it) into PHP <>.
 [2016-07-13 01:42 UTC]
I think this could be a great addition to the already existing tokenizer extension in the core, since it conceptially operates in a very similar way, perhaps indeed by merging @nikic's php-ast into it.
 [2016-07-13 01:44 UTC]
-Status: Open +Status: Verified
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Oct 30 11:01:24 2020 UTC