[PHP-BUG] Req #72559 [NEW]: Function to returns the PHP AST
[email protected] ("david dot proweb at gmail dot com")
| Newsgroups | php.standards |
|---|---|
| Message-ID | <[email protected]> |
From: david dot proweb at gmail dot com
Operating system:
PHP version: Irrelevant
Package: PHP Language Specification
Bug Type: Feature/Change Request
Bug description:Function to returns the PHP AST
Description:
------------
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.
Example:
echo "Hello", "World";
Hello\World('Foo', 'Bar' . 'Baz');
Expectative:
Note: simple values can stays as literals, array should specify the
object key type (maybe the biggest problem).
[
[
'key' => 'echo',
'exprs' => [
'Hello',
'World'
]
],
[
'key' => 'functionCall',
'name' => [
'hello',
'world'
],
'args' => [
'Foo',
[
'key' => 'concatenate',
'values' =>
[
'Bar',
'Baz',
]
]
]
]
]
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;
--
Edit bug report at https://bugs.php.net/bug.php?id=72559&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72559&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72559&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72559&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72559&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72559&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72559&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72559&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72559&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72559&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72559&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72559&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72559&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72559&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72559&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72559&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72559&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72559&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72559&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72559&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72559&r=mysqlcfg