php-parser/UPGRADE-4.0.md

78 lines
3.9 KiB
Markdown
Raw Normal View History

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