NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
Packagist, #15 most downloaded on Packagist
A PHP parser written in PHP
Latest stable
v5.9.0
Last release 2 months ago
13 Sep 2026
Release timing varies
gaps range from 9 days to 7 months
Nearly every release is documented
notes for 60 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
15 years old
113 releases · first in 2012
Drag across the ruler to compare, or tap a release to open it.
Fixed possible undefined offset notice in formatting-preserving printer.
Improved error recovery inside classes.
foreach without as.function (Type ) {}).function ($foo)).Your coding agent can read these notes before it upgrades. Set up the MCP server →
[PHP 7.3] Added support for trailing commas in function calls.
BuilderFactory, to simplify creation of expressions:
funcCall()methodCall()staticCall()new()constFetch()classConstFetch()The following changelog lists all significant changes relative to PHP-Parser 3.1. For more information on backwards incompatible changes, please see t…
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.
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.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.ClassMethod::isMagic() method.BuilderFactory methods: val() method for creating an AST for a simple value, concat() for creating concatenation trees, args() for preparing function arguments.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.Node::setAttributes() method.JsonDecoder. This allows conversion JSON back into an AST.Name methods toLowerString() and isSpecialClassName().Identifier and VarLikeIdentifier nodes, which are used in place of simple strings in many places.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.ConstExprEvaluator to evaluate constant expressions to PHP values.Expr\BinaryOp::getOperatorSigil(), returning + for Expr\BinaryOp\Plus, etc.Identifier (or VarLikeIdentifier) nodes. Please see the UPGRADE-4.0 file for an exhaustive list of affected nodes and some notes on possible impact.expr;) are now represented using a Stmt\Expression node. Previously these statements were directly represented as their constituent expression.name subnode of Param has been renamed to var and now contains a Variable rather than a plain string.name subnode of StaticVar has been renamed to var and now contains a Variable rather than a plain string.var subnode of ClosureUse now contains a Variable rather than a plain string.var subnode of Catch now contains a Variable rather than a plain string.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.type subnode on Class, ClassMethod and Property nodes. Use flags instead.ClassConst::isStatic() method has been removed. Constants cannot have a static modifier.NodeTraverser no longer accepts false as a return value from a leaveNode() method. NodeTraverser::REMOVE_NODE should be returned instead.Node::setLine() method has been removed. If you really need to, you can use setAttribute() instead.Class_::VISIBILITY_MODIFER_MASK constant has been dropped in favor of Class_::VISIBILITY_MODIFIER_MASK.Serializer\XML, and Unserializer\XML, as well as the interfaces Serializer and Unserializer no longer exist.BuilderAbstract class has been removed. It's functionality is moved into BuilderHelpers. However, this is an internal class and should not be used directly.Autoloader class has been removed. It is now required to use the Composer autoloader.Fixed duplicate comment assignment in switch statements.
Fixed pretty printing of -(-$x) and +(+$x).
-(-$x) and +(+$x). (#459)Improve compatibility with php-scoper, by supporting prefixed namespaces in NodeAbstract::getType().
NodeAbstract::getType().Comments on empty blocks are now preserved on a Stmt\Nop node.
Stmt\Nop node. (#382)kind attribute for Stmt\Namespace_ node, which is one of KIND_SEMICOLON or KIND_BRACED. (#417)setDocComment() method to namespace builder. (#437)Fixed syntax error on comment after brace-style namespace declaration.
Name::$parts is no longer deprecated.
This version adds support for PHP 7.2.
object type. This means object types will now be represented as a builtin type (a simple "object" string), rather than a class Name.Name::$parts is no longer deprecated.The Node::setLine() method has been deprecated.
Class_::VISIBILITY_MODIFIER_MASK. The previous spelling of Class_::VISIBILITY_MODIFER_MASK is preserved for backwards compatibility.Builder\Param::makeVariadic().Node::setLine() method has been deprecated.Name resolution of NullableTypes is now performed earlier, so that a fully resolved signature is available when a function is entered.
NullableTypes is now performed earlier, so that a fully resolved signature is available when a function is entered. (#360)Error nodes are now considered empty, while previously they extended until the token where the error occurred. This made some nodes larger than expected. (#359)Fixed some extensibility issues in pretty printer (pUseType() is now public and pPrec() calls into p(), instead of directly dispatching to the type-sp
pUseType() is now public and pPrec() calls into p(), instead of directly dispatching to the type-specific printing method).bin/php-parse script.The XML serializer has been deprecated. In particular, the classes Serializer\XML, Unserializer\XML, as well as the interfaces Serializer and Unserial…
"$foo[0]" the 0 is now parsed as an LNumber rather than String. (#325)LogicException when trying to pretty-print an Error node. Previously this resulted in an undefined method exception or fatal error."$foo[-1]"preserveOriginalNames option to NameResolver. If this option is enabled, an originalName attribute, containing the unresolved name, will be added to each resolved name.php-parse --with-positions option, which dumps nodes with position information.Serializer\XML, Unserializer\XML, as well as the interfaces Serializer and Unserializer are deprecated.Fixed name resolution of nullable types.
Fixed handling of nested list()s: If the nested list was unkeyed, it was directly included in the list items. If it was keyed, it was wrapped in Array
list()s: If the nested list was unkeyed, it was directly included in the list items. If it was keyed, it was wrapped in ArrayItem. Now nested List_ nodes are always wrapped in ArrayItems. (#321)For a description of backwards incompatible changes between version 2.x and 3.0 see the upgrading guide.
PHP-Parser 3.0 adds support for PHP 7.1 and improves support for error recovery.
For a description of backwards incompatible changes between version 2.x and 3.0 see the upgrading guide.
The following changelog only lists changes relative to the beta 2 release. For a complete list of changes see the complete changelog.
dumpPositions option.$, new, Foo::.The pretty printer will now escape all control characters in the range \x00-\x1F inside double quoted strings. If no special escape sequence is availa
\x00-\x1F inside double quoted strings. If no special escape sequence is available, an octal escape will be used.$var =& new Obj assignments.The Comment::setLine() and Comment::setText() methods have been deprecated. Construct new objects instead.
B"" strings (with uppercase B) in a number of places.dumpComments option to node dumper, to enable dumping of comments associated with nodes.Stmt\Nop node, that is used to collect comments located at the end of a block or at the end of a file (without a following node with which they could otherwise be associated).kind attribute to Expr\Exit to distinguish between exit and die.kind attribute to Scalar\LNumber to distinguish between decimal, binary, octal and hexadecimal numbers.kind attribtue to Expr\Array to distinguish between array() and [].kind attribute to Scalar\String and Scalar\Encapsed to distinguish between single-quoted, double-quoted, heredoc and nowdoc string.docLabel attribute to Scalar\String and Scalar\Encapsed, if it is a heredoc or nowdoc string.Comment nodes.setReturnType() method to function and method builders.-h and --help options to php-parse script.AbstractPrettyPrinter::pComments() method no longer returns a trailing newline.PhpParser for easier downstream distribution.Comment::setLine() and Comment::setText() methods have been deprecated. Construct new objects instead.Scalar\LNumber::parse() has been removed. A non-internal LNumber::fromString() method has been added instead.declare() {} and declare(); are not semantically equivalent and will now result in different ASTs. The former case will have an empty stmts array, whi
declare() {} and declare(); are not semantically equivalent and will now result in different ASTs. The former case will have an empty stmts array, while the latter will set stmts to null.#!/usr/bin/env php is now allowed at the start of a namespaced file. Previously this generated an exception.prettyPrintFile() method will not strip a trailing ?> from the raw data that follows a __halt_compiler() statement.prettyPrintFile() method will not strip an opening <?php if the file starts with a comment followed by InlineHTML.A description of backwards incompatible changes between version 1.x and 2.0 can be found in the [upgrading guide](https://github.com/nikic/PHP-Parser/…
This release adds complete support for parsing PHP 7 code.
A description of backwards incompatible changes between version 1.x and 2.0 can be found in the upgrading guide.
A complete list of changes between 1.x and 2.0 can be found in the changelog.
There has been only one additional change since version 2.0.0-beta1:
Scalar\EncapsStringPart nodes. Previously raw strings were used. This affects the parts child of Scalar\Encaps and Expr\ShellExec. The change has been done to allow assignment of attributes to encapsed string parts.Fixed issue with too many newlines being stripped at the end of heredoc/nowdoc strings in some cases.
Added interface PhpParser\Node\FunctionLike, which is implemented by Stmt\ClassMethod, Stmt\Function_ and Expr\Closure nodes. This interface provides
PhpParser\Node\FunctionLike, which is implemented by Stmt\ClassMethod, Stmt\Function_ and Expr\Closure nodes. This interface provides getters for their common subnodes.Node\Stmt\ClassLike::getMethod() to look up a specific method on a class/interface/trait.isPublic() return value for implicitly public properties and methods that define an additional modifier like static or abstract.__HALT_COMPILER_OFFSET__ support on HHVM.Errors can now store the attributes of the node/token where the error occurred. Previously only the start line was stored.
throwOnError parser option. In this mode the parser will try to construct a partial AST even if the code is not valid PHP. See documentation.yield from expression. It is represented by Expr\YieldFrom.Stmt\Class_ nodes with the name set to null. Furthermore this implies that Expr\New_ can now contain a Stmt\Class_ in its class subnode.print expressions.self are now case-insensitive.The NameResolver now resolves parameter type hints when entering the function/method/closure node. As such other visitors running after it will be abl
NameResolver now resolves parameter type hints when entering the function/method/closure node. As such other visitors running after it will be able to make use of the resolved names at that point already.unserialize_callback_func ini option on registration - this is not necessary and may cause issues when running PhpUnit tests with process isolation.This release fixes the registration of the class aliases introduced in version 1.2.0. Previously the old class names could not be used in instanceof c
This release fixes the registration of the class aliases introduced in version 1.2.0. Previously the old class names could not be used in instanceof checks under some circumstances.
The NodeAbstract class still supports the old way of specifying subnodes, however this is _deprecated_. In any case properties that are assigned to a…
To ensure compatibility with PHP 7, the following node classes have been renamed:
OLD => NEW
PhpParser\Node\Expr\Cast\Bool => PhpParser\Node\Expr\Cast\Bool_
PhpParser\Node\Expr\Cast\Int => PhpParser\Node\Expr\Cast\Int_
PhpParser\Node\Expr\Cast\Object => PhpParser\Node\Expr\Cast\Object_
PhpParser\Node\Expr\Cast\String => PhpParser\Node\Expr\Cast\String_
PhpParser\Node\Scalar\String => PhpParser\Node\Scalar\String_
The previous class names are still supported as aliases. However it is strongly encouraged to use the new names in order to make your code compatible with PHP 7.
Subnodes are now stored using real properties instead of an array. This improves performance and memory usage of the initial parse and subsequent node tree operations. The NodeAbstract class still supports the old way of specifying subnodes, however this is deprecated. In any case properties that are assigned to a node after creation will no longer be considered as subnodes.
Methods and property declarations will no longer set the Stmt\Class_::MODIFIER_PUBLIC flag if no visibility is explicitly given. However the isPublic() method will continue to return true. This allows you to distinguish whether a method/property is explicitly or implicitly public and control the pretty printer output more precisely.
The Stmt\Class_, Stmt\Interface_ and Stmt\Trait_ nodes now inherit from Stmt\ClassLike, which provides a getMethods() method. Previously this method was only available on Stmt\Class_.
Support including the bootstrap.php file multiple times.
Make documentation and tests part of the release tarball again.
Improve support for HHVM and PHP 7.
returnType subnode to Stmt\Function_, Stmt\ClassMethod and Expr\Closure.??. The operator is represented by Expr\BinaryOp\Coalesce.<=>. The operator is represented by Expr\BinaryOp\Spaceship.NodeTraverser, which disables cloning of nodes.Methods that do not specify an explicit visibility (e.g. function method()) will now have the MODIFIER_PUBLIC flag set. This also means that their isP
function method()) will now have the MODIFIER_PUBLIC flag set. This also means that their isPublic() method will return true.Lexer and Lexer\Emulative classes now accept an $options array in their constructors. Currently only the usedAttributes option is supported, which determines which attributes will be added to AST nodes. In particular it is now possible to add information on the token and file positions corresponding to a node. For more details see the Lexer component documentation.NodeTraverser::DONT_TRAVERSE_CHILDREN from enterNode() in order to skip all children of the current node, for all visitors.setDocComment() method.The NameResolver visitor now also resolves names in trait adaptations (aliases and precedence declarations).
NameResolver visitor now also resolves names in trait adaptations (aliases and precedence declarations).Disallow new expressions without a class name. Previously new; was accidentally considered to be valid code.
new expressions without a class name. Previously new; was accidentally considered to be valid code.T_ONUMBER token used by HHVM.php-parse.php script.var_dump() output in the php-parse.php script if XDebug is used.Removed deprecated Template and TemplateLoader classes.
See migration guide.
Note: The 0.9.x branch is no longer supported.
The most important changes are:
PhpParser\Parser instead of PHPParser_Parser. The old names using underscored are still supported as aliases.For a complete list of changes, see the Changelog.
Template and TemplateLoader classes.Deprecated PHPParser_Template and PHPParser_TemplateLoader. This functionality does not belong in the main project and - as far as I know - nobody is…
This is the last release on the 0.9 branch. All users on PHP >= 5.3 are encouraged to use version 1.0 instead, which is mostly compatible.
NodeTraverser::removeVisitor() method, which removes a visitor from the node traverser. The method was not added to the corresponding NodeTraverserInterface to avoid BC breaks with custom traversers (it is added in version 1.0).PHPParser_Template and PHPParser_TemplateLoader. This functionality does not belong in the main project and - as far as I know - nobody is using it.NameResolver: Class names are now correctly handled as case-insensitive.xdebug.scream.[PHP 5.5] Add support for ClassName::class. This is parsed as an Expr_ClassConstFetch with 'class' being the constant name.
[PHP 5.5] Add support for ClassName::class. This is parsed as an Expr_ClassConstFetch with 'class' being the constant name.
Syntax errors now include information on expected tokens and mimic the format of PHP's own (pre 5.4) error messages. Example:
Old: Unexpected token T_STATIC on line 1
New: Syntax error, unexpected T_STATIC, expecting T_STRING or T_NS_SEPARATOR or '{'
PHPParser_PrettyPrinter_Zend was renamed to PHPParser_PrettyPrinter_Default as the default pretty printer only very loosely applies the Zend Coding Standard. The class PHPParser_PrettyPrinter_Zend extends PHPParser_PrettyPrinter_Default to maintain backwards compatibility.
The pretty printer now prints namespaces in semicolon-style if possible (i.e. if the file does not contain a global namespace declaration).
Added prettyPrintFile(array $stmts) method which will pretty print a file of statements including the opening <?php tag if it is required. Use of this method will also eliminate the unnecessary <?php ?> at the start and end of files using inline HTML.
There now is a builder for interfaces (PHPParser_Builder_Interface).
An interface for the node traversation has been added: PHPParser_NodeTraverserInterface
Fix pretty printing of include expressions (precedence information was missing).
Improve performance of PrettyPrinter construction by no longer using the uniqid() function.
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
See UPGRADE-5.0 for detailed migration instructions. The changelog is relative to beta 1.
See UPGRADE-5.0 for detailed migration instructions. The changelog is relative to beta 1.
kind) in NodeDumper.rawValue attribute to InterpolatedStringPart and heredoc/nowdoc String_s, which provides the original, unparsed value. It was previously only available for non-interpolated single/double quoted strings.Stmt\Block to represent {} code blocks. Previously, such code blocks were flattened into the parent statements array. Stmt\Block will not be created for structures that are typically used with code blocks, for example if ($x) { $y; } will be represented as previously, while if ($x) { { $y; } } will have an extra Stmt\Block wrapper.Stmt\Throw_ node, use Expr\Throw_ inside Stmt\Expression instead.ParserFactory::create().The deprecated Comment::getLine(), Comment::getTokenPos() and Comment::getFilePos() methods have been removed. Use Comment::getStartLine(), Comment::g…
See UPGRADE-5.0 for detailed migration instructions. The changelog is relative to alpha 3.
NodeTraverser constructor. A separate call to addVisitor() is no longer required.Lexer no longer accepts options. Lexer\Emulative only accepts a PhpVersion. The startLexing(), getTokens() and handleHaltCompiler() methods have been removed. Instead, there is a single method tokenize() returning the tokens.Parser::getLexer() method has been replaced by Parser::getTokens().Comment::getLine(), Comment::getTokenPos() and Comment::getFilePos() methods have been removed. Use Comment::getStartLine(), Comment::getStartTokenPos() and Comment::getStartFilePos() instead.Node::getLine() method has been deprecated. Use Node::getStartLine() instead.See UPGRADE-5.0 for detailed migration instructions.
See UPGRADE-5.0 for detailed migration instructions.
NodeVisitor::REPLACE_WITH_NULL.newline option.else if { } instead of else { if { } }.leaveNode() method on visitors is now invoked in reverse order of enterNode().NodeTraverser::REMOVE_NODE etc. to NodeVisitor::REMOVE_NODE. The old constants are still available for compatibility.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.Identifier, Name or ComplexType must be passed.Comment::getReformattedText() now normalizes CRLF newlines to LF newlines.Differ.Removed deprecated Error constructor taking a line number instead of an attributes array.
See UPGRADE-5.0 for detailed migration instructions.
isPromoted(), isPublic(), isProtected(), isPrivate() and isReadonly() methods on Param.PrettyPrinter interface.php-parse binary now accepts - as the file name, in which case it will read from stdin.clone, throw and arrow functions.yield in parentheses, unless the target version is set to older than PHP 7.0.-> and :: are now taken into account.\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.\u escape sequences.Error constructor taking a line number instead of an attributes array.See UPGRADE-5.0 for detailed migration instructions.
See UPGRADE-5.0 for detailed migration instructions.
PhpParser\Token class, which is compatible with PHP 8 token representation (PhpToken).Expr\List_ nodes, even if it uses [] syntax.Expr/Stmt hierarchy. Compatibility shims for the old names have been retained.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.Parser::getLexer() method.Modifiers class, as a replacement for Stmt\Class_::MODIFIER_*.REMOVE_NODE from NodeVisitor::enterNode().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 experi
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.
Autoloader class has been removed. It is now required to use the Composer autoloader.In the formatting-preserving pretty printer:
In the formatting-preserving pretty printer:
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
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.
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.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.ClassMethod::isMagic() method.BuilderFactory methods: val() method for creating an AST for a simple value, concat() for creating concatenation trees, args() for preparing function arguments.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.Node::setAttributes() method.JsonDecoder. This allows convertion JSON back into an AST.Name methods toLowerString() and isSpecialClassName().Identifier and VarLikeIdentifier nodes, which are used in place of simple strings in many places.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.ConstExprEvaluator to evaluate constant expressions to PHP values.Expr\BinaryOp::getOperatorSigil(), returning + for Expr\BinaryOp\Plus, etc.Identifier (or VarLikeIdentifier) nodes. Please see the UPGRADE-4.0 file for an exhaustive list of affected nodes and some notes on possible impact.expr;) are now represented using a Stmt\Expression node. Previously these statements were directly represented as their constituent expression.name subnode of Param has been renamed to var and now contains a Variable rather than a plain string.name subnode of StaticVar has been renamed to var and now contains a Variable rather than a plain string.var subnode of ClosureUse now contains a Variable rather than a plain string.var subnode of Catch now contains a Variable rather than a plain string.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.type subnode on Class, ClassMethod and Property nodes. Use flags instead.ClassConst::isStatic() method has been removed. Constants cannot have a static modifier.NodeTraverser no longer accepts false as a return value from a leaveNode() method. NodeTraverser::REMOVE_NODE should be returned instead.Node::setLine() method has been removed. If you really need to, you can use setAttribute() instead.Class_::VISIBILITY_MODIFER_MASK constant has been dropped in favor of Class_::VISIBILITY_MODIFIER_MASK.Serializer\XML, and Unserializer\XML, as well as the interfaces Serializer and Unserializer no longer exist.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 following changelog only lists changes relative to the beta 1 release. A description of backwards incompatible changes between version 2.x and 3.0…
This release primarily improves our support for error recovery.
The following changelog only lists changes relative to the beta 1 release. A description of backwards incompatible changes between version 2.x and 3.0 can be found in the upgrading guide.
Node::setDocComment() method.Error::getMessageWithColumnInfo() method.ErrorHandler interface, and ErrorHandler\Throwing and ErrorHandler\Collecting as specific implementations. These provide a general mechanism for handling error recovery.ErrorHandler argument to Parser::parse(), Lexer::startLexing() and NameResolver::__construct().NameResolver now adds a namespacedName attribute on name nodes that cannot be statically resolved (unqualified unaliased function or constant names in namespaces).GroupUse prefix and variables in interpolated strings.NameTraverserInterface have been moved into the NameTraverser class.Parser interface and Lexer API have changed.~__EMU__~ sequences. This changes the protected API of the lexer.Name::slice() method now returns null for empty slices, previously new Name([]) was used. Name::concat() now also supports concatenation with null.Name::append() and Name::prepend(). These mutable methods have been superseded by the immutable Name::concat().Error::getRawLine() and Error::setRawLine(). These methods have been superseded by Error::getStartLine() and Error::setStartLine().NodeTraverser.$separator argument from Name::toString().throw_on_error parser option and Parser::getErrors() method. Use the ErrorHandler mechanism instead.The following changelog only lists changes relative to the alpha 1 release. A description of backwards incompatible changes between version 2.x and 3.…
The following changelog only lists changes relative to the alpha 1 release. A description of backwards incompatible changes between version 2.x and 3.0 can be found in the upgrading guide.
JsonSerializable. The node kind is stored in a nodeType property.InlineHTML node now has an hasLeadingNewline attribute, that specifies whether the
preceding closing tag contained a newline. The pretty printer honors this attribute.$obj-> (with missing property name) is now supported in error recovery mode.php-parse script through the --with-recovery or -r flags.$var =& new Obj assignments.A description of backwards incompatible changes between version 2.x and 3.0 can be found in the upgrading guide.
This release adds full compatibility with PHP 7.1. There are no major API changes, however specific details of the node structure have changed for a number of nodes
A description of backwards incompatible changes between version 2.x and 3.0 can be found in the upgrading guide.
void and iterable types. These will now be represented as strings (instead of Name instances) similar to other builtin types.ClassConst node now has a flags subnode holding the visibility modifier, as well as isPublic(), isProtected() and isPrivate() methods. The constructor changed to accept the additional subnode.NullableType node with a single type subnode.Array nodes may now appear as the left-hand-side of assignments and foreach value targets. Additionally the array items may now contain null values if elements are skipped.List subnode vars has been renamed to items and now contains ArrayItems instead of plain variables.Catch subnode type has been renamed to types and is now an array of Names.Name::slice() now supports lengths and negative offsets. This brings it in line with array_slice() functionality.Due to PHP 7.1 support additions described above, the node structure changed as follows:
void and iterable types are now stored as strings if the PHP 7 parser is used.ClassConst constructor changed to accept an additional flags subnode.Array subnode items may now contain null elements (destructuring).List subnode vars has been renamed to items and now contains ArrayItems instead of plain variables.Catch subnode type has been renamed to types and is now an array of Names.Additionally the following changes were made:
type subnode on Class, ClassMethod and Property has been renamed to flags. The type subnode has retained for backwards compatibility and is populated to the same value as flags. However, writes to type will not update flags.TryCatch subnode finallyStmts has been replaced with a finally subnode that holds an explicit Finally node. This allows for more accurate attribute assignment.Trait constructor now has the same form as the Class and Interface constructors: It takes an array of subnodes. Unlike classes/interfaces, traits can only have a stmts subnode.NodeDumper now prints class/method/property/constant modifiers, as well as the include and use type in a textual representation, instead of only showing the number.PrettyPrinter\Standard are now protected. Previously most of them were public.Comment::setLine() and Comment::setText() methods have been removed.Name::set(), Name::setFirst() and Name::setLast() methods have been removed.A description of changes incompatible with version 1.x can be found in the [upgrading guide](UPGRADE-2.0.md). This changelog lists differences to alph
A description of changes incompatible with version 1.x can be found in the upgrading guide. This changelog lists differences to alpha 1 only.
php-parse.php to php-parse and registered it as a composer bin.shortArraySyntax option to pretty printer, to print all arrays using short syntax.A more detailed description of backwards incompatible changes can be found in the [upgrading guide](UPGRADE-2.0.md).
A more detailed description of backwards incompatible changes can be found in the upgrading guide.
getSubNodeNames() method now.Stmt\GroupUse nodes. Furthermore a type attribute was added to Stmt\UseUse to handle mixed group use declarations.'bool', 'int', 'float' and 'string' as the type. The PHP 5 parser also accepts these, however they'll be Name instances there.PhpParser\ParserFactory class, which should be used to create parser instances.Name::concat() which concatenates two names.Name->slice() which takes a subslice of a name.PhpParser\Parser is now an interface, implemented by Parser\Php5, Parser\Php7 and Parser\Multiple. The Multiple parser will try multiple parsers, until one succeeds.PhpParser\Parser\Tokens rather than PhpParser\Parser.Name->set(), Name->append(), Name->prepend() and Name->setFirst() methods are deprecated in favor of Name::concat() and Name->slice().NodeTraverser no longer clones nodes by default. The old behavior can be restored by passing true to the constructor.Scalar nodes no longer has a default value. E.g. new LNumber() should now be written as new LNumber(0).[PHP 5.6] Updated support for constant scalar expressions to comply with latest changes. This means that arrays and array dimension fetches are now su
FOO[0] and Foo::BAR[0] are valid now.self, parent and static) in the name resolver to be case insensitive. Additionally the name resolver now enforces that special class names are only used as unqualified names, e.g. \self is considered invalid.static class name is now preserved. Previously static was always lowercased, regardless of the case used in the source code.class_exists('PhpParser\NotExistingClass').bin/php-parse.php script, which is intended to help exploring and debugging the node tree.lib/PhpParser/ParserAbstract.php) and the generated data (in lib/PhpParser/Parser.php). Furthermore the parser now uses meaningful variable names and contains comments explaining their usage.[BC] Deprecated PHPParser_Template and PHPParser_TemplateLoader. This functionality does not belong in the main project and - as far as I know - nobod…
[BC] PHP-Parser now requires PHP 5.3 or newer to run. It is however still possible to parse PHP 5.2 source code, while running on a newer version.
[BC] The library has been moved to use namespaces with the PhpParser vendor prefix. However, the old names using underscores are still available as aliases, as such most code should continue running on the new version without further changes.
However, code performing dispatch operations on Node::getType() may be affected by some of the name changes. For example a + node will now return type Expr_BinaryOp_Plus instead of Expr_Plus. In particular this may affect custom pretty printers.
Due to conflicts with reserved keywords, some class names now end with an underscore, e.g. PHPParser_Node_Stmt_Class is now PhpParser\Node\Stmt\Class_. (But as usual, the old name is still available)
[PHP 5.6] Added support for the power operator ** (node Expr\BinaryOp\Pow) and the compound power assignment operator **= (node Expr\AssignOp\Pow).
[PHP 5.6] Added support for variadic functions: Param nodes now have variadic as a boolean subnode.
[PHP 5.6] Added support for argument unpacking: Arg nodes now have unpack as a boolean subnode.
[PHP 5.6] Added support for aliasing of functions and constants. Stmt\Use_ nodes now have an integral type subnode, which is one of Stmt\Use_::TYPE_NORMAL (use), Stmt\Use_::TYPE_FUNCTION (use function) or Stmt\Use_::TYPE_CONSTANT (use const).
The NameResolver now also supports resolution of such aliases.
[PHP 5.6] Added support for constant scalar expressions. This means that certain expressions are now allowed as the initializer for constants, properties, parameters, static variables, etc.
[BC] Improved pretty printing of empty statements lists, which are now printed as {\n} instead of {\n \n}. This changes the behavior of the protected PrettyPrinterAbstract::pStmts() method, so custom pretty printing code making use it of may need to be adjusted.
Changed the order of some subnodes to be consistent with their order in the sour code. For example Stmt\If->cond will now appear before Stmt\If->stmts etc.
Added Scalar\MagicConstant->getName(), which returns the name of the magic constant (e.g. __CLASS__).
The following changes are also included in 0.9.5-dev:
PHPParser_Template and PHPParser_TemplateLoader. This functionality does not belong in the main project and - as far as I know - nobody is using it.NodeTraverser::removeVisitor() method, which removes a visitor from the node traverser. This also modifies the corresponding NodeTraverserInterface.NameResolver: Class names are now correctly handled as case-insensitive.One column per quarter.