Chris@13
|
1 Upgrading from PHP-Parser 3.x to 4.0
|
Chris@13
|
2 ====================================
|
Chris@13
|
3
|
Chris@13
|
4 ### PHP version requirements
|
Chris@13
|
5
|
Chris@13
|
6 PHP-Parser now requires PHP 7.0 or newer to run. It is however still possible to *parse* PHP 5.2-5.6
|
Chris@13
|
7 source code, while running on a newer version.
|
Chris@13
|
8
|
Chris@13
|
9 HHVM is no longer actively supported.
|
Chris@13
|
10
|
Chris@13
|
11 ### Changes to the node structure
|
Chris@13
|
12
|
Chris@13
|
13 * Many subnodes that previously held simple strings now store `Identifier` nodes instead (or
|
Chris@13
|
14 `VarLikeIdentifier` nodes if they have form `$ident`). The constructors of the affected nodes will
|
Chris@13
|
15 automatically convert strings to `Identifier`s and `Identifier`s implement `__toString()`. As such
|
Chris@13
|
16 some code continues to work without changes, but anything using `is_string()`, type-strict
|
Chris@13
|
17 comparisons or strict-mode may require adjustment. The following is an exhaustive list of all
|
Chris@13
|
18 affected subnodes:
|
Chris@13
|
19
|
Chris@16
|
20 * `Const_::$name`
|
Chris@13
|
21 * `NullableType::$type` (for simple types)
|
Chris@13
|
22 * `Param::$type` (for simple types)
|
Chris@13
|
23 * `Expr\ClassConstFetch::$name`
|
Chris@13
|
24 * `Expr\Closure::$returnType` (for simple types)
|
Chris@13
|
25 * `Expr\MethodCall::$name`
|
Chris@13
|
26 * `Expr\PropertyFetch::$name`
|
Chris@13
|
27 * `Expr\StaticCall::$name`
|
Chris@13
|
28 * `Expr\StaticPropertyFetch::$name` (uses `VarLikeIdentifier`)
|
Chris@13
|
29 * `Stmt\Class_::$name`
|
Chris@13
|
30 * `Stmt\ClassMethod::$name`
|
Chris@13
|
31 * `Stmt\ClassMethod::$returnType` (for simple types)
|
Chris@16
|
32 * `Stmt\Function_::$name`
|
Chris@16
|
33 * `Stmt\Function_::$returnType` (for simple types)
|
Chris@13
|
34 * `Stmt\Goto_::$name`
|
Chris@13
|
35 * `Stmt\Interface_::$name`
|
Chris@13
|
36 * `Stmt\Label::$name`
|
Chris@13
|
37 * `Stmt\PropertyProperty::$name` (uses `VarLikeIdentifier`)
|
Chris@13
|
38 * `Stmt\TraitUseAdaptation\Alias::$method`
|
Chris@13
|
39 * `Stmt\TraitUseAdaptation\Alias::$newName`
|
Chris@13
|
40 * `Stmt\TraitUseAdaptation\Precedence::$method`
|
Chris@13
|
41 * `Stmt\Trait_::$name`
|
Chris@13
|
42 * `Stmt\UseUse::$alias`
|
Chris@13
|
43
|
Chris@13
|
44 * Expression statements (`expr;`) are now represented using a `Stmt\Expression` node. Previously
|
Chris@13
|
45 these statements were directly represented as their constituent expression.
|
Chris@13
|
46 * The `name` subnode of `Param` has been renamed to `var` and now contains a `Variable` rather than
|
Chris@13
|
47 a plain string.
|
Chris@13
|
48 * The `name` subnode of `StaticVar` has been renamed to `var` and now contains a `Variable` rather
|
Chris@13
|
49 than a plain string.
|
Chris@13
|
50 * The `var` subnode of `ClosureUse` now contains a `Variable` rather than a plain string.
|
Chris@16
|
51 * The `var` subnode of `Catch_` now contains a `Variable` rather than a plain string.
|
Chris@13
|
52 * The `alias` subnode of `UseUse` is now `null` if no explicit alias is given. As such,
|
Chris@13
|
53 `use Foo\Bar` and `use Foo\Bar as Bar` are now represented differently. The `getAlias()` method
|
Chris@13
|
54 can be used to get the effective alias, even if it is not explicitly given.
|
Chris@13
|
55
|
Chris@13
|
56 ### Miscellaneous
|
Chris@13
|
57
|
Chris@13
|
58 * The indentation handling in the pretty printer has been changed (this is only relevant if you
|
Chris@13
|
59 extend the pretty printer). Previously indentation was automatic, and parts were excluded using
|
Chris@13
|
60 `pNoindent()`. Now no-indent is the default and newlines that require indentation should use
|
Chris@13
|
61 `$this->nl`.
|
Chris@13
|
62
|
Chris@13
|
63 ### Removed functionality
|
Chris@13
|
64
|
Chris@16
|
65 * Removed `type` subnode on `Class_`, `ClassMethod` and `Property` nodes. Use `flags` instead.
|
Chris@13
|
66 * The `ClassConst::isStatic()` method has been removed. Constants cannot have a static modifier.
|
Chris@13
|
67 * The `NodeTraverser` no longer accepts `false` as a return value from a `leaveNode()` method.
|
Chris@13
|
68 `NodeTraverser::REMOVE_NODE` should be returned instead.
|
Chris@13
|
69 * The `Node::setLine()` method has been removed. If you really need to, you can use `setAttribute()`
|
Chris@13
|
70 instead.
|
Chris@13
|
71 * The misspelled `Class_::VISIBILITY_MODIFER_MASK` constant has been dropped in favor of
|
Chris@13
|
72 `Class_::VISIBILITY_MODIFIER_MASK`.
|
Chris@13
|
73 * The XML serializer has been removed. As such, the classes `Serializer\XML`, and
|
Chris@13
|
74 `Unserializer\XML`, as well as the interfaces `Serializer` and `Unserializer` no longer exist.
|
Chris@13
|
75 * The `BuilderAbstract` class has been removed. It's functionality is moved into `BuilderHelpers`.
|
Chris@13
|
76 However, this is an internal class and should not be used directly.
|
Chris@16
|
77 * The `Autoloader` class has been removed in favor of relying on the Composer autoloader.
|