nikic/php-parser
A PHP parser written in PHP
v5.8.0
988M downloads/mo
#18 most downloaded on composer
nikic/PHP-Parser
What this package is like to depend on
Last release 1 months ago
04 Jul 2026
Release timing varies
gaps range from 9 days to 7 months
Some releases are documented
notes for 67 of 112 stable releases
Nothing withdrawn
no release was ever pulled
15 years old
112 releases · first in 2012
4 releases in the last 12 months
see the full history below
Release timeline
112 releases · Jan 2012 to Jul 2026Releases
latest 60 of 112-
v5.8.004 Jul 2026Release notes
Open source →Fixed
- Treat
_as label character in formatting-preserving pretty printer. - Handle comment after object operator in keyword emulator.
Changed
- Drop support for pipe operator in constant expression evaluator. It is not supported in constant expressions and may pose security risks, as it allows calls to arbitrary functions.
voidparameter types now generate a (recoverable) error during parsing.- Restored reverse emulation support for
fnkeywords when targeting PHP before 7.4.
Release notes
Open source →Fixed
- Treat
_as label character in formatting-preserving pretty printer. - Handle comment after object operator in keyword emulator.
Changed
- Drop support for pipe operator in constant expression evaluator. It is not supported in constant expressions and may pose security risks, as it allows calls to arbitrary functions.
voidparameter types now generate a (recoverable) error during parsing.- Restored reverse emulation support for
fnkeywords when targeting PHP before 7.4.
- Treat
-
v5.7.006 Dec 2025Release notes
Open source →Fixed
- Fixed changing modifier on anonymous class with formatting preserving pretty printer.
- Emit an error for unparenthesized arrow functions in pipe operator, and print necessary parentheses in the pretty printer.
- Fix PHP 8.5 deprecation warning in php-parse binary.
Changed
- When targeting PHP 8.4 or newer, omit parentheses around immediately dereferenced new expressions.
Added
- Added
shouldPrintRawValueattribute toScalar\Int_, which makes the pretty printer use therawValueof the node. This can be used to print integers with separators.
Release notes
Open source →Fixed
- Fixed changing modifier on anonymous class with formatting preserving pretty printer.
- Emit an error for unparenthesized arrow functions in pipe operator, and print necessary parentheses in the pretty printer.
- Fix PHP 8.5 deprecation warning in php-parse binary.
Changed
- When targeting PHP 8.4 or newer, omit parentheses around immediately dereferenced new expressions.
Added
- Added
shouldPrintRawValueattribute toScalar\Int_, which makes the pretty printer use therawValueof the node. This can be used to print integers with separators.
-
v5.6.221 Oct 2025Release notes
Open source →Fixed
- Fixed formatting-preserving pretty-printing when changing the visibility modifier on a node that has attributes.
- Fixed
chr()deprecation warning on PHP 8.5.
Added
- Added
Param::isFinal()method.
Release notes
Open source →Fixed
- Fixed formatting-preserving pretty-printing when changing the visibility modifier on a node that has attributes.
- Fixed
chr()deprecation warning on PHP 8.5.
Added
- Added
Param::isFinal()method.
-
v5.6.113 Aug 2025Release notes
Open source →Fixed
- Fixed
Param::isPublic()for parameters with asymmetric visibility keyword. - Fixed PHP 8.5 deprecation warnings for
SplObjectStoragemethods.
Added
- Added cast
kindattributes toCast\Int_,Cast\Bool_andCast\String_. These allow distinguishing the deprecated versions of these casts.
Release notes
Open source →Fixed
- Fixed
Param::isPublic()for parameters with asymmetric visibility keyword. - Fixed PHP 8.5 deprecation warnings for
SplObjectStoragemethods.
Added
- Added cast
kindattributes toCast\Int_,Cast\Bool_andCast\String_. These allow distinguishing the deprecated versions of these casts.
- Fixed
-
v5.6.027 Jul 2025Release notes
Open source →Added
- [8.5] Added support for
clonewith arbitrary function arguments. This will be parsed as anExpr\FuncCallnode, instead of the usualExpr\Clone_node. - [8.5] Permit declaration of
function clonefor use in stubs. - [8.5] Added support for the pipe operator, represented by
Expr\BinaryOp\Pipe. - [8.5] Added support for the
(void)cast, represented byExpr\Cast\Void_. - [8.5] Added support for the
finalmodifier on promoted properties. - Added
CallLike::getArg()to fetch an argument by position and name.
Release notes
Open source →Added
- [8.5] Added support for
clonewith arbitrary function arguments. This will be parsed as anExpr\FuncCallnode, instead of the usualExpr\Clone_node. - [8.5] Permit declaration of
function clonefor use in stubs. - [8.5] Added support for the pipe operator, represented by
Expr\BinaryOp\Pipe. - [8.5] Added support for the
(void)cast, represented byExpr\Cast\Void_. - [8.5] Added support for the
finalmodifier on promoted properties. - Added
CallLike::getArg()to fetch an argument by position and name.
- [8.5] Added support for
-
v5.5.031 May 2025Release notes
Open source →Added
- [8.5] Added support for attributes on constants.
Stmt\Const_now has anattrGroupssubnode. - Added
weakReferencesoption toNodeConnectingVisitorandParentConnectingVisitor. This will create the parent/next/prev references as WeakReferences, to avoid making the AST cyclic and thus increasing GC pressure.
Changed
- Attributes on parameters are now printed on separate lines if the pretty printer target version is PHP 7.4 or older (which is the default). This allows them to be interpreted as comments, instead of causing a parse error. Specify a target version of PHP 8.0 or newer to restore the previous behavior.
Release notes
Open source →Added
- [8.5] Added support for attributes on constants.
Stmt\Const_now has anattrGroupssubnode. - Added
weakReferencesoption toNodeConnectingVisitorandParentConnectingVisitor. This will create the parent/next/prev references as WeakReferences, to avoid making the AST cyclic and thus increasing GC pressure.
Changed
- Attributes on parameters are now printed on separate lines if the pretty printer target version is PHP 7.4 or older (which is the default). This allows them to be interpreted as comments, instead of causing a parse error. Specify a target version of PHP 8.0 or newer to restore the previous behavior.
- [8.5] Added support for attributes on constants.
-
v5.4.030 Dec 2024Release notes
Open source →Added
- Added
Property::isAbstract()andProperty::isFinal()methods. - Added
PropertyHook::isFinal()method. - Emit an error if property hook is used on declaration with multiple properties.
Fixed
- Make legacy class aliases compatible with classmap-authoritative autoloader.
Param::isPromoted()andParam::isPublic()now returns true for parameters that have property hooks but no explicit visibility modifier.PropertyHook::getStmts()now correctly desugars shortsethooks.set => $valuewill be expanded toset { $this->propertyName = $value; }. This requires thepropertyNameattribute on the hook to be set, which is now also set by the parser. If the attribute is not set,getStmts()will throw an error for short set hooks, as it is not possible to produce a correct desugaring.
Release notes
Open source →Added
- Added
Property::isAbstract()andProperty::isFinal()methods. - Added
PropertyHook::isFinal()method. - Emit an error if property hook is used on declaration with multiple properties.
Fixed
- Make legacy class aliases compatible with classmap-authoritative autoloader.
Param::isPromoted()andParam::isPublic()now returns true for parameters that have property hooks but no explicit visibility modifier.PropertyHook::getStmts()now correctly desugars shortsethooks.set => $valuewill be expanded toset { $this->propertyName = $value; }. This requires thepropertyNameattribute on the hook to be set, which is now also set by the parser. If the attribute is not set,getStmts()will throw an error for short set hooks, as it is not possible to produce a correct desugaring.
- Added
-
v5.3.108 Oct 2024Release notes
Open source →Added
- Added support for declaring functions with name
exitordie, to allow their use in stubs.
Release notes
Open source →Added
- Added support for declaring functions with name
exitordie, to allow their use in stubs.
- Added support for declaring functions with name
-
v5.3.029 Sep 2024Release notes
Open source →Added
- Added
indentoption to pretty printer, which can be used to specify the indentation to use (defaulting to four spaces). This also allows using tab indentation.
Fixed
- Resolve names in
PropertyHooks in theNameResolver. - Include the trailing semicolon inside
Stmt\GroupUsenodes, making them consistent withStmt\Use_nodes. - Fixed indentation sometimes becoming negative in formatting-preserving pretty printer, resulting in
ValueErrors.
Release notes
Open source →Added
- Added
indentoption to pretty printer, which can be used to specify the indentation to use (defaulting to four spaces). This also allows using tab indentation.
Fixed
- Resolve names in
PropertyHooks in theNameResolver. - Include the trailing semicolon inside
Stmt\GroupUsenodes, making them consistent withStmt\Use_nodes. - Fixed indentation sometimes becoming negative in formatting-preserving pretty printer, resulting
in
ValueErrors.
- Added
-
v5.2.015 Sep 2024Release notes
Open source →Added
- [8.4] Added support for
__PROPERTY__magic constant, represented using aNode\Scalar\MagicConst\Propertynode. - [8.4] Added support for property hooks, which are represented using a new
hookssubnode onNode\Stmt\PropertyandNode\Param, which contains an array ofNode\PropertyHook. - [8.4] Added support for asymmetric visibility modifiers. Property
flagscan now hold the additional bitsModifiers::PUBLIC_SET,Modifiers::PROTECTED_SETandModifiers::PRIVATE_SET. - [8.4] Added support for generalized exit function. For backwards compatibility, exit without
argument or a single plain argument continues to use a
Node\Expr\Exit_node. Otherwise (e.g. if a named argument is used) it will be represented as a plainNode\Expr\FuncCall. - Added support for passing enum values to various builder methods, like
BuilderFactory::val().
Removed
- Removed support for alternative array syntax
$array{0}from the PHP 8 parser. It is still supported by the PHP 7 parser. This is necessary in order to support property hooks.
- [8.4] Added support for
-
v5.1.001 Jul 2024Release notes
Open source →Added
- [8.4] Added support for dereferencing
newexpressions without parentheses.
Fixed
- Fixed redundant parentheses being added when pretty printing ternary expressions.
Changed
- Made some phpdoc types more precise.
- [8.4] Added support for dereferencing
-
v5.0.205 Mar 2024Release notes
Open source →Fixed
- Fix handling of indentation on next line after opening PHP tag in formatting-preserving pretty printer.
Changed
- Avoid cyclic references in
Parserobjects. This means that no longer used parser objects are immediately destroyed now, instead of requiring cycle GC. - Update
PhpVersion::getNewestSupported()to report PHP 8.3 instead of PHP 8.2.
-
v5.0.121 Feb 2024Release notes
Open source →Changed
- Added check to detect use of PHP-Parser with libraries that define
T_*compatibility tokens with incorrect type (such as string instead of int). This would lead toTypeErrors down the line. Now anErrorwill be thrown early to indicate the problem.
- Added check to detect use of PHP-Parser with libraries that define
-
v5.0.007 Jan 2024Release notes
Open source →See UPGRADE-5.0 for detailed migration instructions.
Fixed
- Fixed parent class of
PropertyItemandUseItem.
- Fixed parent class of
-
v4.19.506 Dec 2025 -
v4.19.429 Sep 2024Nothing published for this version
-
v4.19.329 Sep 2024Nothing published for this version
-
v4.19.217 Sep 2024Nothing published for this version
-
v4.19.117 Mar 2024Nothing published for this version
-
v4.19.016 Mar 2024Nothing published for this version
-
v4.18.010 Dec 2023Nothing published for this version
-
v4.17.113 Aug 2023Nothing published for this version
-
v4.17.013 Aug 2023Nothing published for this version
-
v4.16.025 Jun 2023Nothing published for this version
-
v4.15.519 May 2023Nothing published for this version
-
v4.15.405 Mar 2023Nothing published for this version
-
v4.15.316 Jan 2023Nothing published for this version
-
v4.15.212 Nov 2022Nothing published for this version
-
v4.15.104 Sep 2022Release notes
Open source →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.003 Sep 2022Release notes
Open source →Added
- PHP 8.2: Added support for
truetype. - PHP 8.2: Added support for DNF types.
Fixed
- Support
readonlyas a function name. - Added
__serializeand__unserializeto magic method list. - Fixed bounds check in
Name::slice(). - Fixed formatting preservation when adding attributes to a class/method/etc that previously had none.
- PHP 8.2: Added support for
-
v4.14.031 May 2022Release notes
Open source →Added
- Added support for readonly classes.
- Added
rawValueattribute toLNumber,DNumberandString_nodes, which stores the unparsed value of the literal (e.g."1_000"rather than1000).
-
v4.13.230 Nov 2021Release notes
Open source →Added
- Added builders for enums and enum cases.
Fixed
- NullsafeMethodCall now extends from CallLike.
- The
namespacedNameproperty populated by theNameResolveris now declared on relevant nodes, to avoid a dynamic property deprecation warning with PHP 8.2.
-
v4.13.103 Nov 2021Release notes
Open source →Fixed
- Support reserved keywords as enum cases.
- Support array unpacking in constant expression evaluator.
-
v4.13.020 Sep 2021Release notes
Open source →Added
- [PHP 8.1] Added support for intersection types using a new
IntersectionTypenode. Additionally aComplexTypeparent class forNullableType,UnionTypeandIntersectionTypehas 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 fromExpr\CallLike, which provides anisFirstClassCallable()method to determine whether a placeholder id present.getArgs()can be used to assert that the call is not a first-class callable and returnsArg[]rather thanarray<Arg|VariadicPlaceholder>.
Fixed
- Multiple modifiers for promoted properties are now accepted. In particular this allows something
like
public readonlyfor promoted properties. - Formatting-preserving pretty printing for comments in array literals has been fixed.
- [PHP 8.1] Added support for intersection types using a new
-
v4.12.021 Jul 2021Release notes
Open source →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 theT_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARGandT_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARGtokens used in PHP 8.1. This happens unconditionally, regardless of whether the emulative lexer is used.
- [PHP 8.1] Added support for readonly properties (through a new
-
v4.11.003 Jul 2021Release notes
Open source →Added
BuilderFactory::args()now accepts named arguments.BuilderFactory::attribute()has been added.- An
addAttribute()method accepting anAttributeorAttributeGrouphas been adde to all builders that accept attributes, such asBuilder\Class_.
Fixed
NameResolvernow handles enums.PrettyPrinternow prints backing enum type.- Builder methods for types now property handle
nevertype.
-
v4.10.503 May 2021Release notes
Open source →Added
- [PHP 8.1] Added support for enums. These are represented using the
Stmt\Enum_andStmt\EnumCasenodes. - [PHP 8.1] Added support for never type. This type will now be returned as an
Identifierrather thanName. - Added
ClassConstbuilder.
Changed
- Non-UTF-8 code units in strings will now be hex-encoded.
Fixed
- Fixed precedence of arrow functions.
- [PHP 8.1] Added support for enums. These are represented using the
-
v4.10.420 Dec 2020Release notes
Open source →Fixed
- Fixed position information for variable-variables (#741).
- Fixed position information for traits/interfaces preceded by if statement (#738).
-
v4.10.303 Dec 2020Release notes
Open source →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.
- Fixed formatting-preserving pretty printing for
-
v4.10.226 Sep 2020 -
v4.10.123 Sep 2020Release notes
Open source →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.
-
v4.10.019 Sep 2020Release notes
Open source →Added
- [PHP 8.0] Added support for attributes. These are represented using a new
AttributeGroupnode containingAttributenodes. A newattrGroupssubnode 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\ArrowFunctionandParam. - [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.
- [PHP 8.0] Added support for attributes. These are represented using a new
-
v4.9.130 Aug 2020Release notes
Open source →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.
-
v4.9.018 Aug 2020Release notes
Open source →Added
- [PHP 8.0] Added support for named arguments, represented using a new
namesubnode onArg. - [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 usingStmt\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.
- [PHP 8.0] Added support for named arguments, represented using a new
-
v4.8.009 Aug 2020Release notes
Open source →Added
- [PHP 8.0] Added support for nullsafe operator, represented using the new
Expr\NullsafePropertyFetchandExpr\NullsafeMethodCallnodes. - Added
phpVersionoption 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.
- [PHP 8.0] Added support for nullsafe operator, represented using the new
-
v4.7.025 Jul 2020Release notes
Open source →Added
- Add
ParentConnectingVisitorandNodeConnectingVisitorclasses. - [PHP 8.0] Added support for match expressions. These are represented using a new
Expr\Match_containingMatchArms. - [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.
- Add
-
v4.6.002 Jul 2020Release notes
Open source →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.
-
v4.5.003 Jun 2020Release notes
Open source →Added
- [PHP 8.0] Added support for the mixed type. This means
mixedtypes are now parsed as anIdentifierrather than aName. - [PHP 8.0] Added support for catching without capturing the exception. This means that
Catch_::$varmay now be null.
- [PHP 8.0] Added support for the mixed type. This means
-
v4.4.010 Apr 2020Release notes
Open source →Added
- Added support for passing union types in builders.
- Added end line, token position and file position information for comments.
- Added
getProperty()method toClassLikenodes.
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()andlist(), rather than just variables. In particular, this allowsisset(($x)), which is legal PHP code. - [PHP 8.0] Add support for variable syntax tweaks RFC.
-
v4.3.008 Nov 2019Release notes
Open source →Added
- [PHP 8.0] Added support for union types using a new
UnionTypenode.
- [PHP 8.0] Added support for union types using a new
-
v4.2.525 Oct 2019Release notes
Open source →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.
-
v4.2.401 Sep 2019Release notes
Open source →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.
-
v4.2.312 Aug 2019Release notes
Open source →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.
-
v4.2.225 May 2019Release notes
Open source →Added
- [PHP 7.4] Add support for arrow functions using a new
Expr\ArrowFunctionnode. (#602) - [PHP 7.4] Add support for array spreads, using a new
unpacksubnode onArrayItem. (#609) - Added support for inserting into empty list nodes in the formatting preserving pretty printer.
Changed
php-parsewill 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)
- [PHP 7.4] Add support for arrow functions using a new
-
v4.2.116 Feb 2019Release notes
Open source →Added
- [PHP 7.4] Add support for
??=operator through a newAssignOp\Coalescenode. (#575)
- [PHP 7.4] Add support for
-
v4.2.012 Jan 2019Release notes
Open source →Added
- [PHP 7.4] Add support for typed properties through a new
typesubnode ofStmt\Property. AdditionallyBuilder\Propertynow has asetType()method. (#567) - Add
kindattribute toCast\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).
- [PHP 7.4] Add support for typed properties through a new
-
v4.1.126 Dec 2018Release notes
Open source →Fixed
- Fix "undefined offset" notice when parsing specific malformed code (#551).
Added
- Support error recovery for missing return type (
function foo() : {}) (#544).
-
v4.1.010 Oct 2018Release notes
Open source →Added
- Added support for PHP 7.3 flexible heredoc/nowdoc strings, completing support for PHP 7.3. There
are two caveats for this feature:
- In some rare, pathological cases flexible heredoc/nowdoc strings change the interpretation of existing doc strings. PHP-Parser will now use the new interpretation.
- Flexible heredoc/nowdoc strings require special support from the lexer. Because this is not available on PHP versions before 7.3, support has to be emulated. This emulation is not perfect and some cases which we do not expect to occur in practice (such as flexible doc strings being nested within each other through abuse of variable-variable interpolation syntax) may not be recognized correctly.
- Added
DONT_TRAVERSE_CURRENT_AND_CHILDRENtoNodeTraverserto skip both traversal of child nodes, and prevent subsequent visitors from visiting the current node.
- Added support for PHP 7.3 flexible heredoc/nowdoc strings, completing support for PHP 7.3. There
are two caveats for this feature:
-
v4.0.418 Sep 2018Release notes
Open source →Added
- The following methods have been added to
BuilderFactory:useTrait()(fluent builder)traitUseAdaptation()(fluent builder)useFunction()(fluent builder)useConst()(fluent builder)var()propertyFetch()
Deprecated
Builder\Param::setTypeHint()has been deprecated in favor of the newly introducedBuilder\Param::setType().
- The following methods have been added to
-
v4.0.315 Jul 2018Release notes
Open source →Fixed
- Fixed possible undefined offset notice in formatting-preserving printer. (#513)
Added
- Improved error recovery inside arrays.
- Preserve trailing comment inside classes. Note: This change is possibly BC breaking if your code validates that classes can only contain certain statement types. After this change, classes can also contain Nop statements, while this was not previously possible. (#509)