I do lots of work manipulating and analyzing PHP code. Normally I just use the Tokenizer to do this. For most applications this is sufficient. But sometimes parsing using a lexer just isn’t reliable enough (obviously).
Thus I am looking for some PHP parser written in PHP. I found hnw/PhpParser and kumatch/stagehand-php-parser. Both are created by an automated conversion of zend_language_parser.y to a .y file with PHP instead of C (and then compiled to a LALR(1) parser). But this automated conversion just can’t be worked with.
So, is there any decent PHP parser written in PHP? (I need one for PHP 5.2 and one for 5.3. But just one of them would be a good starting point, too.)
After no complete and stable parser was found here I decided to write one myself. Here is the result:
The project supports parsing code written for any PHP version between PHP 5.2 and PHP 8.1.
Apart from the parser itself the library provides some related components:
For an usage overview see the "Usage of basic components" section of the documentation.