Chris@0: Upgrading from PHP-Parser 3.x to 4.0 Chris@0: ==================================== Chris@0: Chris@0: ### PHP version requirements Chris@0: Chris@0: PHP-Parser now requires PHP 7.0 or newer to run. It is however still possible to *parse* PHP 5.2-5.6 Chris@0: source code, while running on a newer version. Chris@0: Chris@0: HHVM is no longer actively supported. Chris@0: Chris@0: ### Changes to the node structure Chris@0: Chris@0: * Many subnodes that previously held simple strings now store `Identifier` nodes instead (or Chris@0: `VarLikeIdentifier` nodes if they have form `$ident`). The constructors of the affected nodes will Chris@0: automatically convert strings to `Identifier`s and `Identifier`s implement `__toString()`. As such Chris@0: some code continues to work without changes, but anything using `is_string()`, type-strict Chris@0: comparisons or strict-mode may require adjustment. The following is an exhaustive list of all Chris@0: affected subnodes: Chris@0: Chris@0: * `Const_::$name` Chris@0: * `NullableType::$type` (for simple types) Chris@0: * `Param::$type` (for simple types) Chris@0: * `Expr\ClassConstFetch::$name` Chris@0: * `Expr\Closure::$returnType` (for simple types) Chris@0: * `Expr\MethodCall::$name` Chris@0: * `Expr\PropertyFetch::$name` Chris@0: * `Expr\StaticCall::$name` Chris@0: * `Expr\StaticPropertyFetch::$name` (uses `VarLikeIdentifier`) Chris@0: * `Stmt\Class_::$name` Chris@0: * `Stmt\ClassMethod::$name` Chris@0: * `Stmt\ClassMethod::$returnType` (for simple types) Chris@0: * `Stmt\Function_::$name` Chris@0: * `Stmt\Function_::$returnType` (for simple types) Chris@0: * `Stmt\Goto_::$name` Chris@0: * `Stmt\Interface_::$name` Chris@0: * `Stmt\Label::$name` Chris@0: * `Stmt\PropertyProperty::$name` (uses `VarLikeIdentifier`) Chris@0: * `Stmt\TraitUseAdaptation\Alias::$method` Chris@0: * `Stmt\TraitUseAdaptation\Alias::$newName` Chris@0: * `Stmt\TraitUseAdaptation\Precedence::$method` Chris@0: * `Stmt\Trait_::$name` Chris@0: * `Stmt\UseUse::$alias` Chris@0: Chris@0: * Expression statements (`expr;`) are now represented using a `Stmt\Expression` node. Previously Chris@0: these statements were directly represented as their constituent expression. Chris@0: * The `name` subnode of `Param` has been renamed to `var` and now contains a `Variable` rather than Chris@0: a plain string. Chris@0: * The `name` subnode of `StaticVar` has been renamed to `var` and now contains a `Variable` rather Chris@0: than a plain string. Chris@0: * The `var` subnode of `ClosureUse` now contains a `Variable` rather than a plain string. Chris@0: * The `var` subnode of `Catch_` now contains a `Variable` rather than a plain string. Chris@0: * The `alias` subnode of `UseUse` is now `null` if no explicit alias is given. As such, Chris@0: `use Foo\Bar` and `use Foo\Bar as Bar` are now represented differently. The `getAlias()` method Chris@0: can be used to get the effective alias, even if it is not explicitly given. Chris@0: Chris@0: ### Miscellaneous Chris@0: Chris@0: * The indentation handling in the pretty printer has been changed (this is only relevant if you Chris@0: extend the pretty printer). Previously indentation was automatic, and parts were excluded using Chris@0: `pNoindent()`. Now no-indent is the default and newlines that require indentation should use Chris@0: `$this->nl`. Chris@0: Chris@0: ### Removed functionality Chris@0: Chris@0: * Removed `type` subnode on `Class_`, `ClassMethod` and `Property` nodes. Use `flags` instead. Chris@0: * The `ClassConst::isStatic()` method has been removed. Constants cannot have a static modifier. Chris@0: * The `NodeTraverser` no longer accepts `false` as a return value from a `leaveNode()` method. Chris@0: `NodeTraverser::REMOVE_NODE` should be returned instead. Chris@0: * The `Node::setLine()` method has been removed. If you really need to, you can use `setAttribute()` Chris@0: instead. Chris@0: * The misspelled `Class_::VISIBILITY_MODIFER_MASK` constant has been dropped in favor of Chris@0: `Class_::VISIBILITY_MODIFIER_MASK`. Chris@0: * The XML serializer has been removed. As such, the classes `Serializer\XML`, and Chris@0: `Unserializer\XML`, as well as the interfaces `Serializer` and `Unserializer` no longer exist. Chris@0: * The `BuilderAbstract` class has been removed. It's functionality is moved into `BuilderHelpers`. Chris@0: However, this is an internal class and should not be used directly. Chris@0: * The `Autoloader` class has been removed in favor of relying on the Composer autoloader.