Stmt\Const_
now has an attrGroups
subnode.weakReferences
option to NodeConnectingVisitor
and ParentConnectingVisitor
. This
will create the parent/next/prev references as WeakReferences, to avoid making the AST cyclic
and thus increasing GC pressure.Property::isAbstract()
and Property::isFinal()
methods.PropertyHook::isFinal()
method.Param::isPromoted()
and Param::isPublic()
now returns true for parameters that have property
hooks but no explicit visibility modifier.PropertyHook::getStmts()
now correctly desugars short set
hooks. set => $value
will be
expanded to set { $this->propertyName = $value; }
. This requires the propertyName
attribute
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.exit
or die
, to allow their use in stubs.indent
option to pretty printer, which can be used to specify the indentation to use
(defaulting to four spaces). This also allows using tab indentation.PropertyHook
s in the NameResolver
.Stmt\GroupUse
nodes, making them consistent with
Stmt\Use_
nodes.ValueError
s.__PROPERTY__
magic constant, represented using a
Node\Scalar\MagicConst\Property
node.hooks
subnode on
Node\Stmt\Property
and Node\Param
, which contains an array of Node\PropertyHook
.flags
can now hold the
additional bits Modifiers::PUBLIC_SET
, Modifiers::PROTECTED_SET
and Modifiers::PRIVATE_SET
.Node\Expr\Exit_
node. Otherwise (e.g.
if a named argument is used) it will be represented as a plain Node\Expr\FuncCall
.BuilderFactory::val()
.$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.new
expressions without parentheses.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.T_*
compatibility tokens
with incorrect type (such as string instead of int). This would lead to TypeError
s down the
line. Now an Error
will be thrown early to indicate the problem.See UPGRADE-5.0 for detailed migration instructions.
PropertyItem
and UseItem
.See UPGRADE-5.0 for detailed migration instructions.
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.Stmt\Throw_
node, use Expr\Throw_
inside Stmt\Expression
instead.ParserFactory::create()
.See UPGRADE-5.0 for detailed migration instructions.
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.
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
.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.
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()
.true
type.readonly
as a function name.__serialize
and __unserialize
to magic method list.Name::slice()
.rawValue
attribute to LNumber
, DNumber
and String_
nodes, which stores the unparsed
value of the literal (e.g. "1_000"
rather than 1000
).namespacedName
property populated by the NameResolver
is now declared on relevant nodes,
to avoid a dynamic property deprecation warning with PHP 8.2.IntersectionType
node. Additionally
a ComplexType
parent class for NullableType
, UnionType
and IntersectionType
has been
added.VariadicPlaceholder
. The representation is intended to be forward-compatible with
partial function application, just like the PHP feature itself. Call nodes now extend from
Expr\CallLike
, which provides an isFirstClassCallable()
method to determine whether a
placeholder id present. getArgs()
can be used to assert that the call is not a first-class
callable and returns Arg[]
rather than array<Arg|VariadicPlaceholder>
.public readonly
for promoted properties.MODIFIER_READONLY
).&
tokens are now canonicalized to the
T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG
and T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG
tokens
used in PHP 8.1. This happens unconditionally, regardless of whether the emulative lexer is used.BuilderFactory::args()
now accepts named arguments.BuilderFactory::attribute()
has been added.addAttribute()
method accepting an Attribute
or AttributeGroup
has been adde to all
builders that accept attributes, such as Builder\Class_
.NameResolver
now handles enums.PrettyPrinter
now prints backing enum type.never
type.Stmt\Enum_
and
Stmt\EnumCase
nodes.Identifier
rather
than Name
.ClassConst
builder."{$x}"
.error_clear_last()
call in lexer, which may interfere with fatal
error handlers if invoked during shutdown.AttributeGroup
node
containing Attribute
nodes. A new attrGroups
subnode 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\ArrowFunction
and
Param
.name
subnode on Arg
.Expr\Throw_
node. For
backwards compatibility reasons, throw expressions in statement context continue to be
represented using Stmt\Throw_
.Expr\NullsafePropertyFetch
and Expr\NullsafeMethodCall
nodes.phpVersion
option 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.ParentConnectingVisitor
and NodeConnectingVisitor
classes.Expr\Match_
containing MatchArm
s.T_NAME_*
tokens, using emulationg on older PHP versions. Full support for reserved keywords
in namespaced names is not yet present.Node\Param::$flags
.mixed
types are now parsed as an
Identifier
rather than a Name
.Catch_::$var
may now be null.getProperty()
method to ClassLike
nodes.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.isset()
and list()
, rather than just variables.
In particular, this allows isset(($x))
, which is legal PHP code.UnionType
node.Expr\ArrowFunction
node. (#602)unpack
subnode on ArrayItem
. (#609)php-parse
will now print messages to stderr, so that stdout only contains the actual result of
the operation (such as a JSON dump). (#605)??=
operator through a new AssignOp\Coalesce
node. (#575)type
subnode of Stmt\Property
.
Additionally Builder\Property
now has a setType()
method. (#567)kind
attribute to Cast\Double_
, which allows to distinguish between (float)
,
(double)
and (real)
. The form of the cast will be preserved by the pretty printer. (#565)function foo() : {}
) (#544).DONT_TRAVERSE_CURRENT_AND_CHILDREN
to NodeTraverser
to skip both traversal of child
nodes, and prevent subsequent visitors from visiting the current node.BuilderFactory
:
useTrait()
(fluent builder)traitUseAdaptation()
(fluent builder)useFunction()
(fluent builder)useConst()
(fluent builder)var()
propertyFetch()
Builder\Param::setTypeHint()
has been deprecated in favor of the newly introduced
Builder\Param::setType()
.foreach
without as
.function (Type ) {}
).function ($foo)
).BuilderFactory
, to simplify creation of expressions:
funcCall()
methodCall()
staticCall()
new()
constFetch()
classConstFetch()
Autoloader
class has been removed. It is now required to use the Composer autoloader.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.-(-$x)
and +(+$x)
. (#459)NodeAbstract::getType()
.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)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.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.NullableType
s 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)pUseType()
is now public and pPrec()
calls
into p()
, instead of directly dispatching to the type-specific printing method).bin/php-parse
script."$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.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 ArrayItem
s. (#321)dumpPositions
option.$
, new
, Foo::
.This release primarily improves our support for error recovery.
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.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.The following changes are also part of PHP-Parser 2.1.1:
$var =& new Obj
assignments.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 ArrayItem
s instead of plain variables.Catch
subnode type
has been renamed to types
and
is now an array of Name
s.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 ArrayItem
s instead of
plain variables.Catch
subnode type
has been renamed to types
and is now an array of Name
s.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.\x00-\x1F
inside double
quoted strings. If no special escape sequence is available, an octal escape will be used.$var =& new Obj
assignments.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
attribute 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 format 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.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.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.
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)
.This changelog only includes changes from the 2.0 series. For older changes see the 1.x series changelog and the 0.9 series changelog.
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )