Skip to content

Releases: nikic/PHP-Parser

PHP-Parser 4.0.0

28 Feb 20:56
Compare
Choose a tag to compare

This is a new major version of the PHP-Parser library. The biggest new feature in this release is an experimental pretty-printing mode, which preserves formatting for parts of the code which have not been modified. As such, it should now be much easier to use PHP-Parser for automated code refactorings. See the pretty printer documentation for information on how to use this functionality

The following changelog lists all significant changes relative to PHP-Parser 3.1. For more information on backwards incompatible changes, please see the upgrading guide.

Added

  • Added experimental support for format-preserving pretty-printing. In this mode formatting will be preserved for parts of the code which have not been modified.
  • Added replaceNodes option to NameResolver, defaulting to true. If this option is disabled, resolved names will be added as resolvedName attributes, instead of replacing the original names.
  • Added NodeFinder class, which can be used to find nodes based on a callback or class name. This is a utility to avoid custom node visitor implementations for simple search operations.
  • Added ClassMethod::isMagic() method.
  • Added BuilderFactory methods: val() method for creating an AST for a simple value, concat() for creating concatenation trees, args() for preparing function arguments.
  • Added NameContext class, which encapsulates the NameResolver logic independently of the actual AST traversal. This facilitates use in other context, such as class names in doc comments. Additionally it provides an API for getting the shortest representation of a name.
  • Added Node::setAttributes() method.
  • Added JsonDecoder. This allows conversion JSON back into an AST.
  • Added Name methods toLowerString() and isSpecialClassName().
  • Added Identifier and VarLikeIdentifier nodes, which are used in place of simple strings in many places.
  • Added getComments(), getStartLine(), getEndLine(), getStartTokenPos(), getEndTokenPos(), getStartFilePos() and getEndFilePos() methods to Node. These provide a more obvious access point for the already existing attributes of the same name.
  • Added ConstExprEvaluator to evaluate constant expressions to PHP values.
  • Added Expr\BinaryOp::getOperatorSigil(), returning + for Expr\BinaryOp\Plus, etc.
  • Added start token offsets to comments.

Changed

  • Many subnodes that previously held simple strings now use Identifier (or VarLikeIdentifier) nodes. Please see the UPGRADE-4.0 file for an exhaustive list of affected nodes and some notes on possible impact.
  • Expression statements (expr;) are now represented using a Stmt\Expression node. Previously these statements were directly represented as their constituent expression.
  • The name subnode of Param has been renamed to var and now contains a Variable rather than a plain string.
  • The name subnode of StaticVar has been renamed to var and now contains a Variable rather than a plain string.
  • The var subnode of ClosureUse now contains a Variable rather than a plain string.
  • The var subnode of Catch now contains a Variable rather than a plain string.
  • The alias subnode of UseUse is now null if no explicit alias is given. As such, use Foo\Bar and use Foo\Bar as Bar are now represented differently. The getAlias() method can be used to get the effective alias, even if it is not explicitly given.

Removed

  • Support for running on PHP 5 and HHVM has been removed. You can however still parse code of old PHP versions (such as PHP 5.2), while running on PHP 7.
  • Removed type subnode on Class, ClassMethod and Property nodes. Use flags instead.
  • The ClassConst::isStatic() method has been removed. Constants cannot have a static modifier.
  • The NodeTraverser no longer accepts false as a return value from a leaveNode() method. NodeTraverser::REMOVE_NODE should be returned instead.
  • The Node::setLine() method has been removed. If you really need to, you can use setAttribute() instead.
  • The misspelled Class_::VISIBILITY_MODIFER_MASK constant has been dropped in favor of Class_::VISIBILITY_MODIFIER_MASK.
  • The XML serializer has been removed. As such, the classes Serializer\XML, and Unserializer\XML, as well as the interfaces Serializer and Unserializer no longer exist.
  • The BuilderAbstract class has been removed. It's functionality is moved into BuilderHelpers. However, this is an internal class and should not be used directly.
  • The Autoloader class has been removed. It is now required to use the Composer autoloader.

PHP-Parser 3.1.5

28 Feb 20:33
Compare
Choose a tag to compare

Fixed

  • Fixed duplicate comment assignment in switch statements. (#469)
  • Improve compatibility with PHP-Scoper. (#477)

PHP-Parser 4.0.0 Beta 1

27 Jan 18:12
Compare
Choose a tag to compare
Pre-release

This is the first and likely last beta release for a new major version of the PHP-Parser library. The biggest new feature in this version is an experimental pretty-printing mode, which preserves formatting for parts of the code which have not been modified.

For more information on BC breaks in this release see the upgrading guide.

The following changelog only lists the changes from the previous alpha release. A complete changelog is also available.

Fixed

  • In formatting-preserving pretty printer: Fixed indentation when inserting into lists. (#466)

Added

  • In formatting-preserving pretty printer: Improved formatting of elements inserted into multi-line arrays.

Removed

  • The Autoloader class has been removed. It is now required to use the Composer autoloader.

PHP-Parser 3.1.4

25 Jan 21:33
Compare
Choose a tag to compare

Fixed

  • Fixed pretty printing of -(-$x) and +(+$x). (#459)

PHP-Parser 4.0.0 Alpha 3

26 Dec 16:30
Compare
Choose a tag to compare
Pre-release

Fixed

  • In the formatting-preserving pretty printer:
    • Fixed comment indentation.
    • Fixed handling of inline HTML in the fallback case.
    • Fixed insertion into list nodes that require creation of a code block.

Added

  • Added support for inserting at the start of list nodes in formatting-preserving pretty printer.

PHP-Parser 3.1.3

26 Dec 14:45
Compare
Choose a tag to compare

Fixed

  • Improve compatibility with php-scoper, by supporting prefixed namespaces in NodeAbstract::getType().

PHP-Parser 4.0.0 Alpha 2

10 Nov 22:38
Compare
Choose a tag to compare
Pre-release

Added

  • In the formatting-preserving pretty printer:
    • Added support for changing modifiers.
    • Added support for anonymous classes.
    • Added support for removing from list nodes.
    • Improved support for changing comments.
  • Added start token offsets to comments.

PHP-Parser 3.1.2

04 Nov 11:51
Compare
Choose a tag to compare

Fixed

  • Comments on empty blocks are now preserved on a Stmt\Nop node. (#382)

Added

  • Added kind attribute for Stmt\Namespace_ node, which is one of KIND_SEMICOLON or KIND_BRACED. (#417)
  • Added setDocComment() method to namespace builder. (#437)

PHP-Parser 4.0.0 Alpha 1

18 Oct 16:59
Compare
Choose a tag to compare
Pre-release

This is the first alpha for a new major version of the PHP-Parser library. The biggest new feature in this release is an experimental pretty-printing mode, which preserves formatting for parts of the code which have not been modified.

For more information on BC breaks in this release see the upgrading guide.

Added

  • Added experimental support for format-preserving pretty-printing. In this mode formatting will be preserved for parts of the code which have not been modified.
  • Added replaceNodes option to NameResolver, defaulting to true. If this option is disabled, resolved names will be added as resolvedName attributes, instead of replacing the original names.
  • Added NodeFinder class, which can be used to find nodes based on a callback or class name. This is a utility to avoid custom node visitor implementations for simple search operations.
  • Added ClassMethod::isMagic() method.
  • Added BuilderFactory methods: val() method for creating an AST for a simple value, concat() for creating concatenation trees, args() for preparing function arguments.
  • Added NameContext class, which encapsulates the NameResolver logic independently of the actual AST traversal. This facilitates use in other context, such as class names in doc comments. Additionally it provides an API for getting the shortest representation of a name.
  • Added Node::setAttributes() method.
  • Added JsonDecoder. This allows convertion JSON back into an AST.
  • Added Name methods toLowerString() and isSpecialClassName().
  • Added Identifier and VarLikeIdentifier nodes, which are used in place of simple strings in many places.
  • Added getComments(), getStartLine(), getEndLine(), getStartTokenPos(), getEndTokenPos(), getStartFilePos() and getEndFilePos() methods to Node. These provide a more obvious access point for the already existing attributes of the same name.
  • Added ConstExprEvaluator to evaluate constant expressions to PHP values.
  • Added Expr\BinaryOp::getOperatorSigil(), returning + for Expr\BinaryOp\Plus, etc.

Changed

  • Many subnodes that previously held simple strings now use Identifier (or VarLikeIdentifier) nodes. Please see the UPGRADE-4.0 file for an exhaustive list of affected nodes and some notes on possible impact.
  • Expression statements (expr;) are now represented using a Stmt\Expression node. Previously these statements were directly represented as their constituent expression.
  • The name subnode of Param has been renamed to var and now contains a Variable rather than a plain string.
  • The name subnode of StaticVar has been renamed to var and now contains a Variable rather than a plain string.
  • The var subnode of ClosureUse now contains a Variable rather than a plain string.
  • The var subnode of Catch now contains a Variable rather than a plain string.
  • The alias subnode of UseUse is now null if no explicit alias is given. As such, use Foo\Bar and use Foo\Bar as Bar are now represented differently. The getAlias() method can be used to get the effective alias, even if it is not explicitly given.

Removed

  • Support for running on PHP 5 and HHVM has been removed. You can however still parse code of old PHP versions (such as PHP 5.2), while running on PHP 7.
  • Removed type subnode on Class, ClassMethod and Property nodes. Use flags instead.
  • The ClassConst::isStatic() method has been removed. Constants cannot have a static modifier.
  • The NodeTraverser no longer accepts false as a return value from a leaveNode() method. NodeTraverser::REMOVE_NODE should be returned instead.
  • The Node::setLine() method has been removed. If you really need to, you can use setAttribute() instead.
  • The misspelled Class_::VISIBILITY_MODIFER_MASK constant has been dropped in favor of Class_::VISIBILITY_MODIFIER_MASK.
  • The XML serializer has been removed. As such, the classes Serializer\XML, and Unserializer\XML, as well as the interfaces Serializer and Unserializer no longer exist.
  • The BuilderAbstract class has been removed. It's functionality is moved into BuilderHelpers. However, this is an internal class and should not be used directly.

PHP-Parser 3.1.1

02 Sep 17:13
Compare
Choose a tag to compare

Fixed

  • Fixed syntax error on comment after brace-style namespace declaration. (#412)
  • Added support for TraitUse statements in trait builder. (#413)