PHP Parser Versions Save

A PHP parser written in PHP

v4.16.0

10 months ago

Added

  • Added Name::getParts() method for forward-compatibility with PHP-Parser 5.

Deprecated

  • Deprecated direct access to Name::$parts, which will be removed in PHP-Parser 5.

v5.0.0alpha3

10 months ago

See UPGRADE-5.0 for detailed migration instructions.

Added

  • [PHP 8.3] Added support for typed constants.
  • [PHP 8.3] Added support for readonly anonymous classes.
  • Added support for NodeVisitor::REPLACE_WITH_NULL.
  • Added support for CRLF newlines in the pretty printer, using the new newline option.

Changed

  • Use PHP 7.1 as the default target version for the pretty printer.
  • Print else if { } instead of else { if { } }.
  • The leaveNode() method on visitors is now invoked in reverse order of enterNode().
  • Moved NodeTraverser::REMOVE_NODE etc. to NodeVisitor::REMOVE_NODE. The old constants are still available for compatibility.
  • The Name subnode parts has been replaced by name, which stores the name as a string rather than an array of parts separated by namespace separators. The getParts() method returns the old representation.
  • No longer accept strings for types in Node constructors. Instead, either an Identifier, Name or ComplexType must be passed.
  • Comment::getReformattedText() now normalizes CRLF newlines to LF newlines.

Fixed

  • Don't trim leading whitespace in formatting preserving printer.
  • Treat DEL as a label character in the formatting preserving printer depending on the targeted PHP version.
  • Fix error reporting in emulative lexer without explicitly specified error handler.
  • Gracefully handle non-contiguous array indices in the Differ.

v4.15.5

11 months ago

Added

  • Added makePrivate(), makeProtected(), makePublic() and makeReadonly() methods to Builder\Param to allow the creation of promoted parameters.

v4.15.4

1 year ago

Fixed

  • Fixed formatting-preservation for alternative if syntax with trailing comments.

v5.0.0alpha2

1 year ago

See UPGRADE-5.0 for detailed migration instructions.

Added

  • [PHP 8.3] Added support for dynamic class constant fetch.
  • Added many additional type annotations. PhpStan is now used.
  • Added a fuzzing target for PHP-Fuzzer, which was how a lot of pretty printer bugs were found.
  • Added isPromoted(), isPublic(), isProtected(), isPrivate() and isReadonly() methods on Param.
  • Added support for class constants in trait builder.
  • Added PrettyPrinter interface.
  • Added support for formatting preservation when toggling static modifiers.
  • The php-parse binary now accepts - as the file name, in which case it will read from stdin.

Fixed

  • The pretty printer now uses a more accurate treatment of unary operator precedence, and will only wrap them in parentheses if required. This allowed fixing a number of other precedence related bugs.
  • The pretty printer now respects the precedence of clone, throw and arrow functions.
  • The pretty printer no longer unconditionally wraps yield in parentheses, unless the target version is set to older than PHP 7.0.
  • Fixed formatting preservation for alternative elseif/else syntax.
  • Fixed checks for when it is safe to print strings as heredoc/nowdoc to accommodate flexible doc string semantics.
  • The pretty printer now prints parentheses around new/instanceof operands in all required situations.
  • Similar, differences in allowed expressions on the LHS of -> and :: are now taken into account.
  • Fixed various cases where \r at the end of a doc string could be incorrectly merged into a CRLF sequence with a following \n.
  • __halt_compiler is no longer recognized as a semi-reserved keyword, in line with PHP behavior.
  • <?= is no longer recognized as a semi-reserved keyword.
  • Fix handling of very large overflowing \u escape sequences.

Removed

  • Removed deprecated Error constructor taking a line number instead of an attributes array.

v4.15.3

1 year ago

Fixed

  • Support readonly property with PHP 8.2 DNF type.
  • Fixed PHP attribute group and PHP-Parser attribute mixup in EnumCase builder.

v4.15.2

1 year ago

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.

v5.0.0alpha1

1 year ago

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.

v4.15.1

1 year ago

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.

v4.15.0

1 year ago

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.