This is the first alpha for a new major version of the PHP-Parser library. The biggest new feature in this release is an experimental pretty-printing mode, which preserves formatting for parts of the code which have not been modified.
For more information on BC breaks in this release see the upgrading guide.
Added
- Added experimental support for format-preserving pretty-printing. In this mode formatting will be preserved for parts of the code which have not been modified.
- Added
replaceNodesoption toNameResolver, defaulting to true. If this option is disabled, resolved names will be added asresolvedNameattributes, instead of replacing the original names. - Added
NodeFinderclass, which can be used to find nodes based on a callback or class name. This is a utility to avoid custom node visitor implementations for simple search operations. - Added
ClassMethod::isMagic()method. - Added
BuilderFactorymethods:val()method for creating an AST for a simple value,concat()for creating concatenation trees,args()for preparing function arguments. - Added
NameContextclass, which encapsulates theNameResolverlogic independently of the actual AST traversal. This facilitates use in other context, such as class names in doc comments. Additionally it provides an API for getting the shortest representation of a name. - Added
Node::setAttributes()method. - Added
JsonDecoder. This allows convertion JSON back into an AST. - Added
NamemethodstoLowerString()andisSpecialClassName(). - Added
IdentifierandVarLikeIdentifiernodes, which are used in place of simple strings in many places. - Added
getComments(),getStartLine(),getEndLine(),getStartTokenPos(),getEndTokenPos(),getStartFilePos()andgetEndFilePos()methods toNode. These provide a more obvious access point for the already existing attributes of the same name. - Added
ConstExprEvaluatorto evaluate constant expressions to PHP values. - Added
Expr\BinaryOp::getOperatorSigil(), returning+forExpr\BinaryOp\Plus, etc.
Changed
- Many subnodes that previously held simple strings now use
Identifier(orVarLikeIdentifier) nodes. Please see the UPGRADE-4.0 file for an exhaustive list of affected nodes and some notes on possible impact. - 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 ofCatchnow 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.
Removed
- Support for running on PHP 5 and HHVM has been removed. You can however still parse code of old PHP versions (such as PHP 5.2), while running on PHP 7.
- 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.