mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-30 04:19:30 +01:00
2.4 KiB
2.4 KiB
Upgrading from PHP-Parser 2.x to 3.0
This version does not include any major API changes. Only specific details of the node representation have changed in some cases.
PHP version requirements
PHP-Parser now requires PHP 5.5 or newer to run. It is however still possible to parse PHP 5.2, 5.3 and 5.4 source code, while running on a newer version.
Changes to the node structure
The following changes are likely to require code changes if the respective nodes are used:
- The
List
subnodevars
has been renamed toitems
and now containsArrayItem
s instead of plain variables. - The
Catch
subnodetype
has been renamed totypes
and is now an array ofName
s. - The
TryCatch
subnodefinallyStmts
has been replaced with afinally
subnode that holds an explicitFinally
node. - The
type
subnode onClass
,ClassMethod
andProperty
has been renamed toflags
. Thetype
subnode has retained for backwards compatibility and is populated to the same value asflags
. However, writes totype
will not updateflags
and use oftype
is discouraged.
The following changes are unlikely to require code changes:
- The
ClassConst
constructor changed to accept an additionalflags
subnode. - The
Trait
constructor now has the same form as theClass
andInterface
constructors: It takes an array of subnodes. Unlike classes/interfaces, traits can only have astmts
subnode. - The
Array
subnodeitems
may now containnull
elements (due to destructuring). void
anditerable
types are now stored as strings if the PHP 7 parser is used. Previously these would have been represented asName
instances.
Removed methods
The following methods have been removed:
Comment::setLine()
,Comment::setText()
: Create newComment
instances instead.Name::set()
,Name::setFirst()
,Name::setLast()
: Create newName
instances instead. For the latter two a combination ofName::concat()
andName::slice()
can be used.
Miscellaneous
- All methods on
PrettyPrinter\Standard
are now protected. Previoulsy most of them were public. The pretty printer should only be invoked using theprettyPrint()
,prettyPrintFile()
andprettyPrintExpr()
methods. - The node dumper now prints numeric values that act as enums/flags in a string representation. If node dumper results are used in tests, updates may be needed to account for this.