3.9 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	Upgrading from PHP-Parser 3.x to 4.0
PHP version requirements
PHP-Parser now requires PHP 7.0 or newer to run. It is however still possible to parse PHP 5.2-5.6 source code, while running on a newer version.
HHVM is no longer actively supported.
Changes to the node structure
- 
Many subnodes that previously held simple strings now store Identifiernodes instead (orVarLikeIdentifiernodes if they have form$ident). The constructors of the affected nodes will automatically convert strings toIdentifiers andIdentifiers implement__toString(). As such some code continues to work without changes, but anything usingis_string(), type-strict comparisons or strict-mode may require adjustment. The following is an exhaustive list of all affected subnodes:- Const_::$name
- 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)
- Stmt\Function_::$name
- Stmt\Function_::$returnType(for simple types)
- 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 aStmt\Expressionnode. Previously these statements were directly represented as their constituent expression.
- 
The namesubnode ofParamhas been renamed tovarand now contains aVariablerather than a plain string.
- 
The namesubnode ofStaticVarhas been renamed tovarand now contains aVariablerather than a plain string.
- 
The varsubnode ofClosureUsenow contains aVariablerather than a plain string.
- 
The varsubnode ofCatch_now contains aVariablerather than a plain string.
- 
The aliassubnode ofUseUseis nownullif no explicit alias is given. As such,use Foo\Baranduse Foo\Bar as Barare now represented differently. ThegetAlias()method can be used to get the effective alias, even if it is not explicitly given.
Miscellaneous
- The indentation handling in the pretty printer has been changed (this is only relevant if you
extend the pretty printer). Previously indentation was automatic, and parts were excluded using
pNoindent(). Now no-indent is the default and newlines that require indentation should use$this->nl.
Removed functionality
- Removed typesubnode onClass_,ClassMethodandPropertynodes. Useflagsinstead.
- The ClassConst::isStatic()method has been removed. Constants cannot have a static modifier.
- The NodeTraverserno longer acceptsfalseas a return value from aleaveNode()method.NodeTraverser::REMOVE_NODEshould be returned instead.
- The Node::setLine()method has been removed. If you really need to, you can usesetAttribute()instead.
- The misspelled Class_::VISIBILITY_MODIFER_MASKconstant has been dropped in favor ofClass_::VISIBILITY_MODIFIER_MASK.
- The XML serializer has been removed. As such, the classes Serializer\XML, andUnserializer\XML, as well as the interfacesSerializerandUnserializerno longer exist.
- The BuilderAbstractclass has been removed. It's functionality is moved intoBuilderHelpers. However, this is an internal class and should not be used directly.
- The Autoloaderclass has been removed in favor of relying on the Composer autoloader.
