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