A PHP parser written in PHP

Overview

PHP Parser

Coverage Status

This is a PHP 5.2 to PHP 8.1 parser written in PHP. Its purpose is to simplify static code analysis and manipulation.

Documentation for version 4.x (stable; for running on PHP >= 7.0; for parsing PHP 5.2 to PHP 8.1).

Documentation for version 3.x (unsupported; for running on PHP >= 5.5; for parsing PHP 5.2 to PHP 7.2).

Features

The main features provided by this library are:

  • Parsing PHP 5, PHP 7, and PHP 8 code into an abstract syntax tree (AST).
    • Invalid code can be parsed into a partial AST.
    • The AST contains accurate location information.
  • Dumping the AST in human-readable form.
  • Converting an AST back to PHP code.
    • Experimental: Formatting can be preserved for partially changed ASTs.
  • Infrastructure to traverse and modify ASTs.
  • Resolution of namespaced names.
  • Evaluation of constant expressions.
  • Builders to simplify AST construction for code generation.
  • Converting an AST into JSON and back.

Quick Start

Install the library using composer:

php composer.phar require nikic/php-parser

Parse some PHP code into an AST and dump the result in human-readable form:

<?php
use PhpParser\Error;
use PhpParser\NodeDumper;
use PhpParser\ParserFactory;

$code = <<<'CODE'
<?php

function test($foo)
{
    var_dump($foo);
}
CODE;

$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
try {
    $ast = $parser->parse($code);
} catch (Error $error) {
    echo "Parse error: {$error->getMessage()}\n";
    return;
}

$dumper = new NodeDumper;
echo $dumper->dump($ast) . "\n";

This dumps an AST looking something like this:

array(
    0: Stmt_Function(
        byRef: false
        name: Identifier(
            name: test
        )
        params: array(
            0: Param(
                type: null
                byRef: false
                variadic: false
                var: Expr_Variable(
                    name: foo
                )
                default: null
            )
        )
        returnType: null
        stmts: array(
            0: Stmt_Expression(
                expr: Expr_FuncCall(
                    name: Name(
                        parts: array(
                            0: var_dump
                        )
                    )
                    args: array(
                        0: Arg(
                            value: Expr_Variable(
                                name: foo
                            )
                            byRef: false
                            unpack: false
                        )
                    )
                )
            )
        )
    )
)

Let's traverse the AST and perform some kind of modification. For example, drop all function bodies:

use PhpParser\Node;
use PhpParser\Node\Stmt\Function_;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;

$traverser = new NodeTraverser();
$traverser->addVisitor(new class extends NodeVisitorAbstract {
    public function enterNode(Node $node) {
        if ($node instanceof Function_) {
            // Clean out the function body
            $node->stmts = [];
        }
    }
});

$ast = $traverser->traverse($ast);
echo $dumper->dump($ast) . "\n";

This gives us an AST where the Function_::$stmts are empty:

array(
    0: Stmt_Function(
        byRef: false
        name: Identifier(
            name: test
        )
        params: array(
            0: Param(
                type: null
                byRef: false
                variadic: false
                var: Expr_Variable(
                    name: foo
                )
                default: null
            )
        )
        returnType: null
        stmts: array(
        )
    )
)

Finally, we can convert the new AST back to PHP code:

use PhpParser\PrettyPrinter;

$prettyPrinter = new PrettyPrinter\Standard;
echo $prettyPrinter->prettyPrintFile($ast);

This gives us our original code, minus the var_dump() call inside the function:

<?php

function test($foo)
{
}

For a more comprehensive introduction, see the documentation.

Documentation

  1. Introduction
  2. Usage of basic components

Component documentation:

  • Walking the AST
    • Node visitors
    • Modifying the AST from a visitor
    • Short-circuiting traversals
    • Interleaved visitors
    • Simple node finding API
    • Parent and sibling references
  • Name resolution
    • Name resolver options
    • Name resolution context
  • Pretty printing
    • Converting AST back to PHP code
    • Customizing formatting
    • Formatting-preserving code transformations
  • AST builders
    • Fluent builders for AST nodes
  • Lexer
    • Lexer options
    • Token and file positions for nodes
    • Custom attributes
  • Error handling
    • Column information for errors
    • Error recovery (parsing of syntactically incorrect code)
  • Constant expression evaluation
    • Evaluating constant/property/etc initializers
    • Handling errors and unsupported expressions
  • JSON representation
    • JSON encoding and decoding of ASTs
  • Performance
    • Disabling Xdebug
    • Reusing objects
    • Garbage collection impact
  • Frequently asked questions
    • Parent and sibling references
Comments
  • Optionally add nodes for whitespace

    Optionally add nodes for whitespace

    I don't know if that's part of the scope of PHP-Parser, but it would be useful (at least for me as it would greatly simplify the code for my PHP CS fixer -- http://cs.sensiolabs.org/) to be able to have nodes for whitespace. This should probably be an option as most of the time, you don't care about whitespace, and also because it would add many nodes.

    opened by fabpot 33
  • Userfriendly API for Namespace, Function, Class, Methods and Properties

    Userfriendly API for Namespace, Function, Class, Methods and Properties

    Hey!

    i've been thinking about using your Parser to create a Tool to Manipulate Classes. This has been a common practice among the TYPO3 Community with the old kickstarter and now the ExtensionBuilder. The biggest caveat to date is the manipulation of those generated classes once the developer started to modify them. it's has been quite a buggy hassle to modfiy manually modified classes. This could simply be improved by your PHP-Parser.

    To make this easier i'd propose to add some simple to use API to PHP-Parser make it easier to accomplish this task. I've forked your Repo and started to implement some of these.

    Main thing i would like to know, is if you would be willing to integrate it directly into your Parser or if you think, that this doesn't really belong directly in the Parser and instead in a seperate library.

    For Example:

    General

    • getByType(Class|Method|Property|...)

    Namespace

    • getClasses()
    • getFunctions()
    • getName(), getType(), etc

    Class

    • getMethods()
    • getProperties()
    • addMethod()
    • createMethod()
    • addProperty()
    • createProperty()
    • getName(), getType(), etc

    Method

    • getArguments()
    • getName(), getType(), etc

    Property

    • getName(), getType(), etc

    Greetings Marc

    opened by mneuhaus 27
  • Add ability to add new nodes from enterNode()

    Add ability to add new nodes from enterNode()

    See https://github.com/nikic/PHP-Parser/issues/507#issuecomment-1014940669


    Original post:

    Is it a feature you would be willing to consider? Right now it seems this is possible only in leaveNode() and if the parent is an array.

    Maybe this could be done by introducing a NullNode class that can wrap several nodes.

    opened by theofidry 20
  • Keywords reserved and AST not built

    Keywords reserved and AST not built

    Hello Nikita,

    I've found an issue on build AST process with keywords reserved. Let me explains with an example: trait keyword is reserved since PHP 5.4 and a token T_TRAIT exists

    If you try to analyse such source code, with PHP 5.3

    <?php
    
    class trait
    {
    }
    

    You should NOT get any error with PHP-Parser, because trait is declared as a T_STRING token

    Here are the list I get

    (
        [0] => Array
            (
                [0] => 368
                [1] => <?php
    
                [2] => 1
            )
    
        [1] => Array
            (
                [0] => 371
                [1] =>
    
                [2] => 2
            )
    
        [2] => Array
            (
                [0] => 353
                [1] => class
                [2] => 3
            )
    
        [3] => Array
            (
                [0] => 371
                [1] =>
                [2] => 3
            )
    
        [4] => Array
            (
                [0] => 307
                [1] => trait
                [2] => 3
            )
    
        [5] => Array
            (
                [0] => 371
                [1] =>
    
                [2] => 3
            )
    
        [6] => {
        [7] => Array
            (
                [0] => 371
                [1] =>
    
                [2] => 4
            )
    
        [8] => }
        [9] => Array
            (
                [0] => 371
                [1] =>
    
                [2] => 5
            )
    
    )
    

    And token_name(307), gave me T_STRING with PHP 5.3.29

    But, if I run this script (still with PHP 5.3.29) with PHP-Parser 1.3.0

    <?php
    
    require_once dirname(__DIR__) . '/vendor/autoload.php';
    
    use PhpParser\Node;
    
    $lexer      = new PhpParser\Lexer\Emulative;
    $parser     = new PhpParser\Parser($lexer);
    $traverser  = new PhpParser\NodeTraverser;
    $traverser->addVisitor(new PhpParser\NodeVisitor\NameResolver);
    
    $code = '<?php
    
    class trait
    {
    }
    ';
    
    try {
        $stmts  = $parser->parse($code);
        $tokens = $lexer->getTokens();
    
        $stmts = $traverser->traverse($stmts); 
        echo 'all statements', PHP_EOL;
        print_r( $stmts );    
        print_r( $tokens );    
    
    
    } catch (PhpParser\Error $e) {
        echo 'Parse Error: ', $e->getMessage();
    }
    

    I have such results :

    Parse Error: Syntax error, unexpected T_TRAIT, expecting T_STRING on line 3
    

    This is difficult to have a NodeVisitor that search for keywords reserved in such condition. Did you've a solution to suggest ?

    Thanks in advance. Laurent

    opened by llaville 17
  • Please provides test

    Please provides test

    Hi

    Since 1.1.0 and 0dd2b9a74c46149847d79e72cf418a0f519e3ed9 tests are no more provided in the downloadable tarball.

    Can you please consider removing the export-ignore line for test in .gitattribute, and provide them again ?

     test export-ignore
    
    opened by remicollet 17
  • [PHP 7.4] Add arrow function

    [PHP 7.4] Add arrow function

    This PR based on PR to php-src: https://github.com/php/php-src/pull/3941

    Current RFC voting is 33:5, so if nothing complicated happens in implementation, this feature will get accepted to PHP 7.4.

    I need feedback on this. I'm not sure the ArrowFunction should inherit FunctionLike - because ArrowFunction has exactly 1 statement, not more.

    1. Should new interface be created?
    2. Should FunctionLike be parrent to the new interface?
    3. Should it extend Closure?

    I tried to mimic php-src grammar Zend/zend_language_parser.y

    opened by TomasVotruba 15
  • How distinct method with and without public visibility ?

    How distinct method with and without public visibility ?

    Hello,

    I've a problem [1] on my project php-compatinfo that used php-reflect that itself used PHP-Parser 1.0 (stable)

    My question is : how can you distinct parsing nodes from code 1 to code 2

    code 1

    <?php
    class Foo
    {
        function bar() {}
    }
    

    code 2

    <?php
    class Foo
    {
        public function bar() {}
    }
    

    Both gave me the same nodes dump

    ==> Node dump:
    array(
        0: Stmt_Class(
            type: 0
            name: Foo
            extends: null
            implements: array(
            )
            stmts: array(
                0: Stmt_ClassMethod(
                    type: 1
                    byRef: false
                    name: bar
                    params: array(
                    )
                    stmts: array(
                    )
                )
            )
        )
    )
    

    The PhpParser\Node\Stmt\ClassMethod::isPublic return me always TRUE with code1 or code2 (public visibility declared or not)

    Thanks in advance for answer. Laurent

    [1] https://github.com/llaville/php-compat-info/issues/129

    opened by llaville 15
  • follow value of variable in php script

    follow value of variable in php script

    Hi, i just want to ask if its possible to follow a variable through a php script?

    For example:

    $val = "test"; $val2 = $val; echo $val2;

    I just found the traverse - but how can i do that exactly?

    I could do this with regex - but i want to know if its working with the php parser too?

    Thanks and Nice Time!

    opened by subabrain 14
  • Fix case sensitivity for special class names

    Fix case sensitivity for special class names

    The current behaviour in the name resolver visitor is incorrect as special class names are case-insensitive as demonstrated here: http://3v4l.org/4g7Hj

    opened by TimeToogo 14
  • PHP-Parser does not properly handle UTF-8 multibyte characters such as U+00C0

    PHP-Parser does not properly handle UTF-8 multibyte characters such as U+00C0

    Hi, I've encountered an issue where php-parser corrupts hex escaped characters in PHP code. I've made a repro in a gist - run run.php and diff source and output to see the issue. Somehow deleting anything from this file changes the output of those unicode characters, so it may be file-size related?

    Let me know if you need any additional info.

    PHP version: 7.4.15 php-parser version: v4.10.4

    opened by marekdedic 13
  • [PHP 7.4] Add coalesce equal `??=`

    [PHP 7.4] Add coalesce equal `??=`

    Adds ??= support https://github.com/php/php-src/pull/3747

    Tests are failing.

    It looks like it's not possible to add it. Probably needs to wait for T_COALESCE_EQUAL token, or not?

    opened by TomasVotruba 13
  • Remove node that are in one line

    Remove node that are in one line

    Hello,

    I want to remove node (Trait1 only in this example) if they are like this

    class MyClass {
         use Trait1, Trait2;
    }
    

    My node visitor in leaveNode return an array of Node\Name.

    public function leaveNode(Node $node)
    {
        if ($node instanceof Node\Stmt\TraitUse) {
            $node->traits; // list of trait
        }
    }
    

    With many tries, I only archived to have (for example):

    use , Trait2; or even worst use ;

    Thank for you help

    opened by kl3sk 2
  • expr printing performance

    expr printing performance

    in phpstan profiles we see in different workloads that pretty printing of expressions take a considerable amount of time of the static analysis run.

    see e.g.

    grafik

    measuered using bin/phpstan --debug -vvv analyze fonts/cid0kr.ph (cid0kr from TCPDF repo - it happens in other profiles too though)

    I just want to leave this issue here, in case you see some performance low hanging fruits in the expression printing parts.

    opened by staabm 0
  • Feature request

    Feature request

    Description Of Issue:

    I am unable to buy you a coffee.

    Steps to reproduce:

    1. Check readme for button or link, verify not present.
    2. Check github profile for button or link, verify not present.
    3. Check personal website for button or link, verify not present.

    Notes:

    User story:

    As a user of software you have donated to the community for free, I would like to be able to buy you a coffee to say thank you.

    opened by mmcgrathRSD 0
  • Best way to determine if any changes were made to AST?

    Best way to determine if any changes were made to AST?

    Since format-preserving prettyprinting has been experimental for years and will most likely never be capable of rendering unmodified AST to unmodified PHP in every case, I need an alternative strategy for detecting a no-changes-made condition betwen the before AST and the after AST. This is necessary to avoid generating whitespace/formatting-only file changes during large refactorings.

    I would like to avoid having to manually track when I make a change (e.g. by setting a flag in the visitor), because that is an immense burden to always remember when writing lots and lots and lots and lots of visitor code.

    opened by rulatir 1
  • Sometimes it makes sense for visitors to leave in reverse order of entering

    Sometimes it makes sense for visitors to leave in reverse order of entering

    Speaking from my general experience with using the vistor pattern, I find that sometimes certain traversal scenarios are easier to engineer if the traverser calls ->leave() in reverse order of visitors, i.e. first enter last leave.

    Two questions:

    1. Do you believe implementing this would be as simple as an optional array_reverse() in traverseNode(), and it won't cause problems like breaking the shipped visitors (node connectors, finders etc.)?
    2. If you believe it should be feasible, would you accept a PR that implements this and adds the necessary knob to NodeTraverser?
    opened by rulatir 9
Releases(v4.15.2)
  • v4.15.2(Nov 12, 2022)

    Fixed

    • Fixed parsing of large hex float literals that contain an "e" character.
    • Fixed tests to pass on 32-bit.
    • Fixed generation of invalid code when using formatting-preserving pretty printer with code that uses inline HTML.
    Source code(tar.gz)
    Source code(zip)
  • v5.0.0alpha1(Sep 4, 2022)

    See UPGRADE-5.0 for detailed migration instructions.

    Changed

    • PHP 7.1 is now required to run PHP-Parser.
    • Formatting of the standard pretty printer has been adjusted to match PSR-12 more closely.
    • The internal token representation now uses a PhpParser\Token class, which is compatible with PHP 8 token representation (PhpToken).
    • Destructuring is now always represented using Expr\List_ nodes, even if it uses [] syntax.
    • Renamed a number of node classes, and moved things that were not real expressions/statements outside the Expr/Stmt hierarchy. Compatibility shims for the old names have been retained.

    Added

    • Added PhpVersion class, which is accepted in a number of places (e.g. ParserFactory, Parser, Lexer, PrettyPrinter) and gives more precise control over the PHP version being targeted.
    • Added PHP 8 parser though it only differs from the PHP 7 parser in concatenation precedence.
    • Added Parser::getLexer() method.
    • Added a Modifiers class, as a replacement for Stmt\Class_::MODIFIER_*.
    • Added support for returning an array or REMOVE_NODE from NodeVisitor::enterNode().

    Removed

    • The PHP 5 parser has been removed. The PHP 7 parser has been adjusted to deal with PHP 5 code more gracefully.
    Source code(tar.gz)
    Source code(zip)
  • v4.15.1(Sep 4, 2022)

    Fixed

    • Fixed formatting preservation when adding multiple attributes to a class/method/etc that previously had none. This fixes a regression in the 4.15.0 release.
    Source code(tar.gz)
    Source code(zip)
  • v4.15.0(Sep 3, 2022)

    Added

    • PHP 8.2: Added support for true type.
    • PHP 8.2: Added support for DNF types.

    Fixed

    • Support readonly as a function name.
    • Added __serialize and __unserialize to magic method list.
    • Fixed bounds check in Name::slice().
    • Fixed formatting preservation when adding attributes to a class/method/etc that previously had none.
    Source code(tar.gz)
    Source code(zip)
  • v4.14.0(May 31, 2022)

    Added

    • Added support for readonly classes.
    • Added rawValue attribute to LNumber, DNumber and String_ nodes, which stores the unparsed value of the literal (e.g. "1_000" rather than 1000).
    Source code(tar.gz)
    Source code(zip)
  • v4.13.2(Nov 30, 2021)

    Added

    • Added builders for enums and enum cases.

    Fixed

    • NullsafeMethodCall now extends from CallLike.
    • The namespacedName property populated by the NameResolver is now declared on relevant nodes, to avoid a dynamic property deprecation warning with PHP 8.2.
    Source code(tar.gz)
    Source code(zip)
  • v4.13.1(Nov 3, 2021)

  • v4.13.0(Sep 20, 2021)

    This release features full PHP 8.1 support.

    Added

    • [PHP 8.1] Added support for intersection types using a new IntersectionType node. Additionally a ComplexType parent class for NullableType, UnionType and IntersectionType has been added.
    • [PHP 8.1] Added support for explicit octal literals.
    • [PHP 8.1] Added support for first-class callables. These are represented using a call whose first argument is a VariadicPlaceholder. The representation is intended to be forward-compatible with partial function application, just like the PHP feature itself. Call nodes now extend from Expr\CallLike, which provides an isFirstClassCallable() method to determine whether a placeholder id present. getArgs() can be used to assert that the call is not a first-class callable and returns Arg[] rather than array<Arg|VariadicPlaceholder>.

    Fixed

    • Multiple modifiers for promoted properties are now accepted. In particular this allows something like public readonly for promoted properties.
    • Formatting-preserving pretty printing for comments in array literals has been fixed.
    Source code(tar.gz)
    Source code(zip)
  • v4.12.0(Jul 21, 2021)

    Added

    • [PHP 8.1] Added support for readonly properties (through a new MODIFIER_READONLY).
    • [PHP 8.1] Added support for final class constants.

    Fixed

    • Fixed compatibility with PHP 8.1. & tokens are now canonicalized to the T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG and T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG tokens used in PHP 8.1. This happens unconditionally, regardless of whether the emulative lexer is used.
    Source code(tar.gz)
    Source code(zip)
  • v4.11.0(Jul 3, 2021)

    Added

    • BuilderFactory::args() now accepts named arguments.
    • BuilderFactory::attribute() has been added.
    • An addAttribute() method accepting an Attribute or AttributeGroup has been added to all builders that accept attributes, such as Builder\Class_.

    Fixed

    • NameResolver now handles enums.
    • PrettyPrinter now prints backing enum type.
    • Builder methods for types now property handle never type.
    Source code(tar.gz)
    Source code(zip)
  • v4.10.5(May 3, 2021)

    Added

    • [PHP 8.1] Added support for enums. These are represented using the Stmt\Enum_ and Stmt\EnumCase nodes.
    • [PHP 8.1] Added support for never type. This type will now be returned as an Identifier rather than Name.
    • Added ClassConst builder.

    Changed

    • Non-UTF-8 code units in strings will now be hex-encoded.

    Fixed

    • Fixed precedence of arrow functions.
    Source code(tar.gz)
    Source code(zip)
  • v4.10.4(Dec 20, 2020)

    Fixed

    • Fixed position information for variable-variables (#741).
    • Fixed position information for traits/interfaces preceded by if statement (#738).
    Source code(tar.gz)
    Source code(zip)
  • v4.10.3(Dec 3, 2020)

    Fixed

    • Fixed formatting-preserving pretty printing for "{$x}".
    • Ternary expressions are now treated as non-associative in the pretty printer, in order to generate code that is compatible with the parentheses requirement introduced in PHP 8.
    • Removed no longer necessary error_clear_last() call in lexer, which may interfere with fatal error handlers if invoked during shutdown.
    Source code(tar.gz)
    Source code(zip)
  • v4.10.2(Sep 26, 2020)

  • v4.10.1(Sep 23, 2020)

    Added

    • Added support for recovering from a missing semicolon after a property or class constant declaration.

    Fixed

    • Fix spurious whitespace in formatting-preserving pretty printer when both removing and adding elements at the start of a list.
    • Fix incorrect case-sensitivity in keyword token emulation.
    Source code(tar.gz)
    Source code(zip)
  • v4.10.0(Sep 19, 2020)

    Added

    • [PHP 8.0] Added support for attributes. These are represented using a new AttributeGroup node containing Attribute nodes. A new attrGroups subnode is available on all node types that support attributes, i.e. Stmt\Class_, Stmt\Trait_, Stmt\Interface_, Stmt\Function_, Stmt\ClassMethod, Stmt\ClassConst, Stmt\Property, Expr\Closure, Expr\ArrowFunction and Param.
    • [PHP 8.0] Added support for nullsafe properties inside interpolated strings, in line with an upstream change.

    Fixed

    • Improved compatibility with other libraries that use forward compatibility defines for PHP tokens.
    Source code(tar.gz)
    Source code(zip)
  • v4.9.1(Aug 30, 2020)

    Added

    • Added support for removing the first element of a list to the formatting-preserving pretty printer.

    Fixed

    • Allow member modifiers as part of namespaced names. These were missed when support for other keywords was added.
    Source code(tar.gz)
    Source code(zip)
  • v4.9.0(Aug 18, 2020)

    Added

    • [PHP 8.0] Added support for named arguments, represented using a new name subnode on Arg.
    • [PHP 8.0] Added support for static return type, represented like a normal class return type.
    • [PHP 8.0] Added support for throw expression, represented using a new Expr\Throw_ node. For backwards compatibility reasons, throw expressions in statement context continue to be represented using Stmt\Throw_.
    • [PHP 8.0] Added support for keywords as parts of namespaced names.

    Fixed

    • Emit parentheses for class constant fetch with complex left-hand-side.
    • Emit parentheses for new/instanceof on complex class expression.
    Source code(tar.gz)
    Source code(zip)
  • v4.8.0(Aug 9, 2020)

    Added

    • [PHP 8.0] Added support for nullsafe operator, represented using the new Expr\NullsafePropertyFetch and Expr\NullsafeMethodCall nodes.
    • Added phpVersion option to the emulative lexer, which allows controlling the target version to emulate (defaults to the latest available, currently PHP 8.0). This is useful to parse code that uses reserved keywords from newer PHP versions as identifiers.
    Source code(tar.gz)
    Source code(zip)
  • v4.7.0(Jul 25, 2020)

    Added

    • Add ParentConnectingVisitor and NodeConnectingVisitor classes.
    • [PHP 8.0] Added support for match expressions. These are represented using a new Expr\Match_ containing MatchArms.
    • [PHP 8.0] Added support for trailing comma in closure use lists.

    Fixed

    • Fixed missing error for unterminated comment with trailing newline (#688).
    • Compatibility with PHP 8.0 has been restored: Namespaced names are now always represented by T_NAME_* tokens, using emulationg on older PHP versions. Full support for reserved keywords in namespaced names is not yet present.
    Source code(tar.gz)
    Source code(zip)
  • v4.6.0(Jul 2, 2020)

    Added

    • [PHP 8.0] Added support for trailing commas in parameter lists.
    • [PHP 8.0] Added support for constructor promotion. The parameter visibility is stored in Node\Param::$flags.

    Fixed

    • Comment tokens now always follow the PHP 8 interpretation, and do not include trailing whitespace.
    • As a result of the previous change, some whitespace issues when inserting a statement into a method containing only a comment, and using the formatting-preserving pretty printer, have been resolved.
    Source code(tar.gz)
    Source code(zip)
  • v4.5.0(Jun 3, 2020)

    Added

    • [PHP 8.0] Added support for the mixed type. This means mixed types are now parsed as an Identifier rather than a Name.
    • [PHP 8.0] Added support for catching without capturing the exception. This means that Catch_::$var may now be null.
    Source code(tar.gz)
    Source code(zip)
  • v4.4.0(Apr 10, 2020)

    Added

    • Added support for passing union types in builders.
    • Added end line, token position and file position information for comments.
    • Added getProperty() method to ClassLike nodes.
    • [PHP 8.0] Add support for variable syntax tweaks RFC.

    Fixed

    • Fixed generation of invalid code when using the formatting preserving pretty printer, and inserting code next to certain nop statements. The formatting is still ugly though.
    • getDocComment() no longer requires that the very last comment before a node be a doc comment. There may not be non-doc comments between the doc comment and the declaration.
    • Allowed arbitrary expressions in isset() and list(), rather than just variables. In particular, this allows isset(($x)), which is legal PHP code.
    Source code(tar.gz)
    Source code(zip)
  • v4.3.0(Apr 10, 2020)

  • v4.2.5(Oct 25, 2019)

    Changed

    • Tests and documentation are no longer included in source archives. They can still be accessed by cloning the repository.
    • php-yacc is now used to generate the parser. This has no impact on users of the library.
    Source code(tar.gz)
    Source code(zip)
  • v4.2.4(Sep 1, 2019)

    Added

    • Added getProperties(), getConstants() and getTraitUses() to ClassLike. (#629, #630)

    Fixed

    • Fixed flexible heredoc emulation to check for digits after the end label. This synchronizes behavior with the upcoming PHP 7.3.10 release.
    Source code(tar.gz)
    Source code(zip)
  • v4.2.3(Aug 12, 2019)

    Added

    • [PHP 7.4] Add support for numeric literal separators. (#615)

    Fixed

    • Fixed resolution of return types for arrow functions. (#613)
    • Fixed compatibility with PHP 7.4.
    Source code(tar.gz)
    Source code(zip)
  • v4.2.2(May 25, 2019)

    Added

    • [PHP 7.4] Add support for arrow functions using a new Expr\ArrowFunction node. (#602)
    • [PHP 7.4] Add support for array spreads, using a new unpack subnode on ArrayItem. (#609)
    • Added support for inserting into empty list nodes in the formatting preserving pretty printer.

    Changed

    • php-parse will now print messages to stderr, so that stdout only contains the actual result of the operation (such as a JSON dump). (#605)

    Fixed

    • Fixed attribute assignment for zero-length nop statements, and a related assertion failure in the formatting-preserving pretty printer. (#589)
    Source code(tar.gz)
    Source code(zip)
  • v4.2.1(Feb 16, 2019)

  • v4.2.0(Jan 12, 2019)

    Added

    • [PHP 7.4] Add support for typed properties through a new type subnode of Stmt\Property. Additionally Builder\Property now has a setType() method. (#567)
    • Add kind attribute to Cast\Double_, which allows to distinguish between (float), (double) and (real). The form of the cast will be preserved by the pretty printer. (#565)

    Fixed

    • Remove assertion when pretty printing anonymous class with a name (#554).
    Source code(tar.gz)
    Source code(zip)
Owner
Nikita Popov
Nikita Popov
A PHP parser written in PHP

PHP Parser This is a PHP 5.2 to PHP 8.1 parser written in PHP. Its purpose is to simplify static code analysis and manipulation. Documentation for ver

Nikita Popov 15.9k Jan 8, 2023
Golang 1.18 parser written in PHP 8.1

GoParser Golang (1.18) parser written in PHP 8.1 Installation To install this package, run: composer require tuqqu/go-parser Example $parser = new \G

Arthur Kurbidaev 37 Nov 2, 2022
Parsica - PHP Parser Combinators - The easiest way to build robust parsers.

Parsica The easiest way to build robust parsers in PHP. composer require parsica-php/parsica Documentation & API: parsica-php.github.io <?php $parser

null 350 Dec 27, 2022
PHP Simple M3U Parser, it clean the playlist and remove duplicate

SimpleM3UParser PHP Simple M3U Playlist Parser, it clean, remove duplicate, and group the playlist. Usage see example.php <?php require_once "M3UPars

erwin solihin 3 May 30, 2022
Referer-parser PHP library

referer-parser PHP library This is the PHP implementation of referer-parser, the library for extracting search marketing data from referer (sic) URLs.

null 4 Sep 3, 2022
Lightning Fast, Minimalist PHP User Agent String Parser.

Lightning Fast, Minimalist PHP User Agent String Parser.

Jesse Donat 523 Dec 21, 2022
A PHP package for MRZ (Machine Readable Zones) code parser for Passport, Visa & Travel Document (TD1 & TD2).

MRZ (Machine Readable Zones) Parser for PHP A PHP package for MRZ (Machine Readable Zones) code parser for Passport, Visa & Travel Document (TD1 & TD2

Md. Rakibul Islam 25 Aug 24, 2022
Annotations Docblock Parser

Doctrine Annotations Docblock Annotations Parser library (extracted from Doctrine Common). Documentation See the doctrine-project website. Contributin

Doctrine 6.6k Dec 29, 2022
A proof-of-concept parser for the SMART Health Cards format.

SMART Health Cards parser A proof-of-concept parser for the SMART Health Cards format. This is not intended for production use. I just hacked this tog

Mikkel Paulson 55 Jul 31, 2022
uaDetect – A multi-language port of Browserscope's user agent parser

uaDetect is a lightweight for detecting mobile devices. It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.

Fadjrir Herlambang 1 Jan 7, 2022
JsonCollectionParser - Event-based parser for large JSON collections (consumes small amount of memory)

Event-based parser for large JSON collections (consumes small amount of memory). Built on top of JSON Streaming Parser This packa

Max Grigorian 113 Dec 6, 2022
MySQL parser for free-id/core package

MySQL parser Installation You can install the package via composer: composer require free-id/mysql Usage use FreeId\Mysql\Parser; $parser = new Parse

Free ID 0 Jul 27, 2022
A sampling profiler for PHP written in PHP, which reads information about running PHP VM from outside of the process.

Reli Reli is a sampling profiler (or a VM state inspector) written in PHP. It can read information about running PHP script from outside of the proces

null 272 Dec 22, 2022
A sampling profiler for PHP written in PHP, which reads information about running PHP VM from outside of the process.

Reli Reli is a sampling profiler (or a VM state inspector) written in PHP. It can read information about running PHP script from outside of the proces

null 258 Sep 15, 2022
A multithreaded application server for PHP, written in PHP.

appserver.io, a PHP application server This is the main repository for the appserver.io project. What is appserver.io appserver.io is a multithreaded

appserver.io 951 Dec 25, 2022
A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch screens with a resolution of 1024x600 connected to a Raspberry Pi.

EDStatusPanel A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch scr

marcus-s 24 Oct 4, 2022
PHP generics written in PHP

PHP generics written in PHP Require PHP >= 7.4 Composer (PSR-4 Autoload) Table of contents How it works Quick start Example Features Tests How it work

Anton Sukhachev 173 Dec 30, 2022
A beautiful, fully open-source, tunneling service - written in pure PHP

Expose A completely open-source ngrok alternative - written in pure PHP. Documentation For installation instructions, in-depth usage and deployment de

Beyond Code 3.9k Jan 7, 2023
Websocket chat room written in PHP based on workerman.

基于workerman的GatewayWorker框架开发的一款高性能支持分布式部署的聊天室系统。

walkor 1.1k Jan 8, 2023