A PHP parser written in PHP
Parser
objects. This means that no longer used parser objects are immediately destroyed now, instead of requiring cycle GC.PhpVersion::getNewestSupported()
to report PHP 8.3 instead of PHP 8.2.See the upgrading guide for detailed migration instructions. The changelog is relative to PHP-Parser 4.18.0.
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::getTokens()
method.Modifiers
class, as a replacement for Stmt\Class_::MODIFIER_*
.REMOVE_NODE
from NodeVisitor::enterNode()
.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.NodeVisitor::REPLACE_WITH_NULL
.newline
option.NodeTraverser
constructor. A separate call to addVisitor()
is no longer required.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) { { $x; } }
will have an extra Stmt\Block
wrapper.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.yield
in parentheses, unless the target version is set to older than PHP 7.0.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.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.Error
constructor taking a line number instead of an attributes array.Comment::getLine()
, Comment::getTokenPos()
and Comment::getFilePos()
methods have been removed. Use Comment::getStartLine()
, Comment::getStartTokenPos()
and Comment::getStartFilePos()
instead.Stmt\Throw_
node, use Expr\Throw_
inside Stmt\Expression
instead.ParserFactory::create()
.clone
, throw
and arrow functions.\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.Differ
.Node::getLine()
method has been deprecated. Use Node::getStartLine()
instead.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()
.ParserFactory::createForNewestSupportedVersion()
and ParserFactory::createForHostVersion()
for forward-compatibility with PHP-Parser 5.0.grammar/
directory has been excluded from exported git archives.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.(CONST)::$x
and similar.