A PHP parser written in PHP

Overview

PHP Parser

Coverage Status

This is a PHP 5.2 to PHP 8.0 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.0).

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 web tool to explore the ASTs generated by PHP-Parser.

phpast.com A web tool to explore the ASTs generated by PHP-Parser. About This web tool provides a GUI for exploring the AST of your PHP code. You can

Ryan Chandler 23 Nov 29, 2022
A generic content parser based on the devto markdown + frontmatter format, with liquid tag support

Parsed A generic content parser based on the devto post format, with front matter and liquid tag support. Parsed uses league/commonmark as base markdo

null 18 Dec 28, 2022
A set of tools for lexical and syntactical analysis written in pure PHP.

Welcome to Dissect! master - this branch always contains the last stable version. develop - the unstable development branch. Dissect is a set of tools

Jakub Lédl 221 Nov 29, 2022
PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly frontend application for the raw metrics stream measured by PHP Depend.

PHPMD PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly

PHP Mess Detector 2.1k Jan 8, 2023
A PHP VM implementation in PHP

PHPPHP A PHP VM implementation written in PHP. This is a basic VM implemented in PHP using the AST generating parser developed by @nikic To see what's

Anthony Ferrara 801 Dec 25, 2022
PHP Architecture Tester - Easy to use architectural testing tool for PHP :heavy_check_mark:

Easy to use architecture testing tool for PHP Introduction ?? PHP Architecture Tester is a static analysis tool to verify architectural requirements.

Carlos A Sastre 765 Dec 30, 2022
Provides functionality that helps writing PHP code that has runtime-specific (PHP / HHVM) execution paths

sebastian/environment This component provides functionality that helps writing PHP code that has runtime-specific (PHP / HHVM) execution paths. Instal

Sebastian Bergmann 6.5k Jan 3, 2023
Search PHP source code for function & method calls, variables, and more from PHP.

Searching PHP source code made easy Search PHP source code for function & method calls, variable assignments, classes and more directly from PHP. Inst

Permafrost Software 22 Nov 24, 2022
A tool to automatically fix PHP Coding Standards issues

PHP Coding Standards Fixer The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards; whether you want to follow PHP codi

null 11.6k Jan 3, 2023
PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

About PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a define

Squiz Labs 9.9k Jan 4, 2023
PHP Static Analysis Tool - discover bugs in your code without running it!

PHPStan - PHP Static Analysis Tool PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even b

PHPStan 11.6k Dec 30, 2022
Phan is a static analyzer for PHP. Phan prefers to avoid false-positives and attempts to prove incorrectness rather than correctness.

Phan is a static analyzer for PHP that prefers to minimize false-positives. Phan attempts to prove incorrectness rather than correctness. Phan looks f

null 5.4k Jan 7, 2023
A PHP code-quality tool

GrumPHP Sick and tired of defending code quality over and over again? GrumPHP will do it for you! This composer plugin will register some git hooks in

PHPro 3.9k Jan 1, 2023
Beautiful and understandable static analysis tool for PHP

PhpMetrics PhpMetrics provides metrics about PHP project and classes, with beautiful and readable HTML report. Documentation | Twitter | Contributing

PhpMetrics 2.3k Dec 22, 2022
A tool for quickly measuring the size of a PHP project.

PHPLOC phploc is a tool for quickly measuring the size and analyzing the structure of a PHP project. Installation This tool is distributed as a PHP Ar

Sebastian Bergmann 2.3k Jan 4, 2023
Copy/Paste Detector (CPD) for PHP code.

PHP Copy/Paste Detector (PHPCPD) phpcpd is a Copy/Paste Detector (CPD) for PHP code. Installation This tool is distributed as a PHP Archive (PHAR): $

Sebastian Bergmann 2.2k Jan 1, 2023
:crystal_ball: Better Reflection is a reflection API that aims to improve and provide more features than PHP's built-in reflection API.

Better Reflection Better Reflection is a reflection API that aims to improve and provide more features than PHP's built-in reflection API. Why is it b

Roave, LLC 1.1k Dec 15, 2022
A command line refactoring tool for PHP

PHP Refactoring Browser Note: This software is under development and in alpha state. Refactorings do not contain all necessary pre-conditions and migh

QafooLabs 562 Dec 30, 2022
Micro PHP benchmark library

Ubench Ubench is a PHP micro library for benchmark Installation Note: If you are looking for this package for laravel application then install it from

Jeremy Perret 554 Nov 25, 2022