6 Version 4.0.1 (2018-03-25)
7 --------------------------
11 * [PHP 7.3] Added support for trailing commas in function calls.
12 * [PHP 7.3] Added support for by-reference array destructuring.
13 * Added checks to node traverser to prevent replacing a statement with an expression or vice versa.
14 This should prevent common mistakes in the implementation of node visitors.
15 * Added the following methods to `BuilderFactory`, to simplify creation of expressions:
23 Version 4.0.0 (2018-02-28)
24 --------------------------
26 * No significant code changes since the beta 1 release.
28 Version 4.0.0-beta1 (2018-01-27)
29 --------------------------------
33 * In formatting-preserving pretty printer: Fixed indentation when inserting into lists. (#466)
37 * In formatting-preserving pretty printer: Improved formatting of elements inserted into multi-line
42 * The `Autoloader` class has been removed. It is now required to use the Composer autoloader.
44 Version 4.0.0-alpha3 (2017-12-26)
45 ---------------------------------
49 * In the formatting-preserving pretty printer:
50 * Fixed comment indentation.
51 * Fixed handling of inline HTML in the fallback case.
52 * Fixed insertion into list nodes that require creation of a code block.
56 * Added support for inserting at the start of list nodes in formatting-preserving pretty printer.
58 Version 4.0.0-alpha2 (2017-11-10)
59 ---------------------------------
63 * In the formatting-preserving pretty printer:
64 * Added support for changing modifiers.
65 * Added support for anonymous classes.
66 * Added support for removing from list nodes.
67 * Improved support for changing comments.
68 * Added start token offsets to comments.
70 Version 4.0.0-alpha1 (2017-10-18)
71 ---------------------------------
75 * Added experimental support for format-preserving pretty-printing. In this mode formatting will be
76 preserved for parts of the code which have not been modified.
77 * Added `replaceNodes` option to `NameResolver`, defaulting to true. If this option is disabled,
78 resolved names will be added as `resolvedName` attributes, instead of replacing the original
80 * Added `NodeFinder` class, which can be used to find nodes based on a callback or class name. This
81 is a utility to avoid custom node visitor implementations for simple search operations.
82 * Added `ClassMethod::isMagic()` method.
83 * Added `BuilderFactory` methods: `val()` method for creating an AST for a simple value, `concat()`
84 for creating concatenation trees, `args()` for preparing function arguments.
85 * Added `NameContext` class, which encapsulates the `NameResolver` logic independently of the actual
86 AST traversal. This facilitates use in other context, such as class names in doc comments.
87 Additionally it provides an API for getting the shortest representation of a name.
88 * Added `Node::setAttributes()` method.
89 * Added `JsonDecoder`. This allows conversion JSON back into an AST.
90 * Added `Name` methods `toLowerString()` and `isSpecialClassName()`.
91 * Added `Identifier` and `VarLikeIdentifier` nodes, which are used in place of simple strings in
93 * Added `getComments()`, `getStartLine()`, `getEndLine()`, `getStartTokenPos()`, `getEndTokenPos()`,
94 `getStartFilePos()` and `getEndFilePos()` methods to `Node`. These provide a more obvious access
95 point for the already existing attributes of the same name.
96 * Added `ConstExprEvaluator` to evaluate constant expressions to PHP values.
97 * Added `Expr\BinaryOp::getOperatorSigil()`, returning `+` for `Expr\BinaryOp\Plus`, etc.
101 * Many subnodes that previously held simple strings now use `Identifier` (or `VarLikeIdentifier`)
102 nodes. Please see the UPGRADE-4.0 file for an exhaustive list of affected nodes and some notes on
104 * Expression statements (`expr;`) are now represented using a `Stmt\Expression` node. Previously
105 these statements were directly represented as their constituent expression.
106 * The `name` subnode of `Param` has been renamed to `var` and now contains a `Variable` rather than
108 * The `name` subnode of `StaticVar` has been renamed to `var` and now contains a `Variable` rather
110 * The `var` subnode of `ClosureUse` now contains a `Variable` rather than a plain string.
111 * The `var` subnode of `Catch` now contains a `Variable` rather than a plain string.
112 * The `alias` subnode of `UseUse` is now `null` if no explicit alias is given. As such,
113 `use Foo\Bar` and `use Foo\Bar as Bar` are now represented differently. The `getAlias()` method
114 can be used to get the effective alias, even if it is not explicitly given.
118 * Support for running on PHP 5 and HHVM has been removed. You can however still parse code of old
119 PHP versions (such as PHP 5.2), while running on PHP 7.
120 * Removed `type` subnode on `Class`, `ClassMethod` and `Property` nodes. Use `flags` instead.
121 * The `ClassConst::isStatic()` method has been removed. Constants cannot have a static modifier.
122 * The `NodeTraverser` no longer accepts `false` as a return value from a `leaveNode()` method.
123 `NodeTraverser::REMOVE_NODE` should be returned instead.
124 * The `Node::setLine()` method has been removed. If you really need to, you can use `setAttribute()`
126 * The misspelled `Class_::VISIBILITY_MODIFER_MASK` constant has been dropped in favor of
127 `Class_::VISIBILITY_MODIFIER_MASK`.
128 * The XML serializer has been removed. As such, the classes `Serializer\XML`, and
129 `Unserializer\XML`, as well as the interfaces `Serializer` and `Unserializer` no longer exist.
130 * The `BuilderAbstract` class has been removed. It's functionality is moved into `BuilderHelpers`.
131 However, this is an internal class and should not be used directly.
133 Version 3.1.5 (2018-02-28)
134 --------------------------
138 * Fixed duplicate comment assignment in switch statements. (#469)
139 * Improve compatibility with PHP-Scoper. (#477)
141 Version 3.1.4 (2018-01-25)
142 --------------------------
146 * Fixed pretty printing of `-(-$x)` and `+(+$x)`. (#459)
148 Version 3.1.3 (2017-12-26)
149 --------------------------
153 * Improve compatibility with php-scoper, by supporting prefixed namespaces in
154 `NodeAbstract::getType()`.
156 Version 3.1.2 (2017-11-04)
157 --------------------------
161 * Comments on empty blocks are now preserved on a `Stmt\Nop` node. (#382)
165 * Added `kind` attribute for `Stmt\Namespace_` node, which is one of `KIND_SEMICOLON` or
166 `KIND_BRACED`. (#417)
167 * Added `setDocComment()` method to namespace builder. (#437)
169 Version 3.1.1 (2017-09-02)
170 --------------------------
174 * Fixed syntax error on comment after brace-style namespace declaration. (#412)
175 * Added support for TraitUse statements in trait builder. (#413)
177 Version 3.1.0 (2017-07-28)
178 --------------------------
182 * [PHP 7.2] Added support for trailing comma in group use statements.
183 * [PHP 7.2] Added support for `object` type. This means `object` types will now be represented as a
184 builtin type (a simple `"object"` string), rather than a class `Name`.
188 * Floating-point numbers are now printed correctly if the LC_NUMERIC locale uses a comma as decimal
193 * `Name::$parts` is no longer deprecated.
195 Version 3.0.6 (2017-06-28)
196 --------------------------
200 * Fixed the spelling of `Class_::VISIBILITY_MODIFIER_MASK`. The previous spelling of
201 `Class_::VISIBILITY_MODIFER_MASK` is preserved for backwards compatibility.
202 * The pretty printing will now preserve comments inside array literals and function calls by
203 printing the array items / function arguments on separate lines. Array literals and functions that
204 do not contain comments are not affected.
208 * Added `Builder\Param::makeVariadic()`.
212 * The `Node::setLine()` method has been deprecated.
214 Version 3.0.5 (2017-03-05)
215 --------------------------
219 * Name resolution of `NullableType`s is now performed earlier, so that a fully resolved signature is
220 available when a function is entered. (#360)
221 * `Error` nodes are now considered empty, while previously they extended until the token where the
222 error occurred. This made some nodes larger than expected. (#359)
223 * Fixed notices being thrown during error recovery in some situations. (#362)
225 Version 3.0.4 (2017-02-10)
226 --------------------------
230 * Fixed some extensibility issues in pretty printer (`pUseType()` is now public and `pPrec()` calls
231 into `p()`, instead of directly dispatching to the type-specific printing method).
232 * Fixed notice in `bin/php-parse` script.
236 * Error recovery from missing semicolons is now supported in more cases.
237 * Error recovery from trailing commas in positions where PHP does not support them is now supported.
239 Version 3.0.3 (2017-02-03)
240 --------------------------
244 * In `"$foo[0]"` the `0` is now parsed as an `LNumber` rather than `String`. (#325)
245 * Ensure integers and floats are always pretty printed preserving semantics, even if the particular
246 value can only be manually constructed.
247 * Throw a `LogicException` when trying to pretty-print an `Error` node. Previously this resulted in
248 an undefined method exception or fatal error.
252 * [PHP 7.1] Added support for negative interpolated offsets: `"$foo[-1]"`
253 * Added `preserveOriginalNames` option to `NameResolver`. If this option is enabled, an
254 `originalName` attribute, containing the unresolved name, will be added to each resolved name.
255 * Added `php-parse --with-positions` option, which dumps nodes with position information.
259 * The XML serializer has been deprecated. In particular, the classes `Serializer\XML`,
260 `Unserializer\XML`, as well as the interfaces `Serializer` and `Unserializer` are deprecated.
262 Version 3.0.2 (2016-12-06)
263 --------------------------
267 * Fixed name resolution of nullable types. (#324)
268 * Fixed pretty-printing of nullable types.
270 Version 3.0.1 (2016-12-01)
271 --------------------------
275 * Fixed handling of nested `list()`s: If the nested list was unkeyed, it was directly included in
276 the list items. If it was keyed, it was wrapped in `ArrayItem`. Now nested `List_` nodes are
277 always wrapped in `ArrayItem`s. (#321)
279 Version 3.0.0 (2016-11-30)
280 --------------------------
284 * Added support for dumping node positions in the NodeDumper through the `dumpPositions` option.
285 * Added error recovery support for `$`, `new`, `Foo::`.
287 Version 3.0.0-beta2 (2016-10-29)
288 --------------------------------
290 This release primarily improves our support for error recovery.
294 * Added `Node::setDocComment()` method.
295 * Added `Error::getMessageWithColumnInfo()` method.
296 * Added support for recovery from lexer errors.
297 * Added support for recovering from "special" errors (i.e. non-syntax parse errors).
298 * Added precise location information for lexer errors.
299 * Added `ErrorHandler` interface, and `ErrorHandler\Throwing` and `ErrorHandler\Collecting` as
300 specific implementations. These provide a general mechanism for handling error recovery.
301 * Added optional `ErrorHandler` argument to `Parser::parse()`, `Lexer::startLexing()` and
302 `NameResolver::__construct()`.
303 * The `NameResolver` now adds a `namespacedName` attribute on name nodes that cannot be statically
304 resolved (unqualified unaliased function or constant names in namespaces).
308 * Fixed attribute assignment for `GroupUse` prefix and variables in interpolated strings.
312 * The constants on `NameTraverserInterface` have been moved into the `NameTraverser` class.
313 * Due to the error handling changes, the `Parser` interface and `Lexer` API have changed.
314 * The emulative lexer now directly postprocesses tokens, instead of using `~__EMU__~` sequences.
315 This changes the protected API of the lexer.
316 * The `Name::slice()` method now returns `null` for empty slices, previously `new Name([])` was
317 used. `Name::concat()` now also supports concatenation with `null`.
321 * Removed `Name::append()` and `Name::prepend()`. These mutable methods have been superseded by
322 the immutable `Name::concat()`.
323 * Removed `Error::getRawLine()` and `Error::setRawLine()`. These methods have been superseded by
324 `Error::getStartLine()` and `Error::setStartLine()`.
325 * Removed support for node cloning in the `NodeTraverser`.
326 * Removed `$separator` argument from `Name::toString()`.
327 * Removed `throw_on_error` parser option and `Parser::getErrors()` method. Use the `ErrorHandler`
330 Version 3.0.0-beta1 (2016-09-16)
331 --------------------------------
335 * [7.1] Function/method and parameter builders now support PHP 7.1 type hints (void, iterable and
337 * Nodes and Comments now implement `JsonSerializable`. The node kind is stored in a `nodeType`
339 * The `InlineHTML` node now has an `hasLeadingNewline` attribute, that specifies whether the
340 preceding closing tag contained a newline. The pretty printer honors this attribute.
341 * Partial parsing of `$obj->` (with missing property name) is now supported in error recovery mode.
342 * The error recovery mode is now exposed in the `php-parse` script through the `--with-recovery`
345 The following changes are also part of PHP-Parser 2.1.1:
347 * The PHP 7 parser will now generate a parse error for `$var =& new Obj` assignments.
348 * Comments on free-standing code blocks will now be retained as comments on the first statement in
351 Version 3.0.0-alpha1 (2016-07-25)
352 ---------------------------------
356 * [7.1] Added support for `void` and `iterable` types. These will now be represented as strings
357 (instead of `Name` instances) similar to other builtin types.
358 * [7.1] Added support for class constant visibility. The `ClassConst` node now has a `flags` subnode
359 holding the visibility modifier, as well as `isPublic()`, `isProtected()` and `isPrivate()`
360 methods. The constructor changed to accept the additional subnode.
361 * [7.1] Added support for nullable types. These are represented using a new `NullableType` node
362 with a single `type` subnode.
363 * [7.1] Added support for short array destructuring syntax. This means that `Array` nodes may now
364 appear as the left-hand-side of assignments and foreach value targets. Additionally the array
365 items may now contain `null` values if elements are skipped.
366 * [7.1] Added support for keys in list() destructuring. The `List` subnode `vars` has been renamed
367 to `items` and now contains `ArrayItem`s instead of plain variables.
368 * [7.1] Added support for multi-catch. The `Catch` subnode `type` has been renamed to `types` and
369 is now an array of `Name`s.
370 * `Name::slice()` now supports lengths and negative offsets. This brings it in line with
371 `array_slice()` functionality.
375 Due to PHP 7.1 support additions described above, the node structure changed as follows:
377 * `void` and `iterable` types are now stored as strings if the PHP 7 parser is used.
378 * The `ClassConst` constructor changed to accept an additional `flags` subnode.
379 * The `Array` subnode `items` may now contain `null` elements (destructuring).
380 * The `List` subnode `vars` has been renamed to `items` and now contains `ArrayItem`s instead of
382 * The `Catch` subnode `type` has been renamed to `types` and is now an array of `Name`s.
384 Additionally the following changes were made:
386 * The `type` subnode on `Class`, `ClassMethod` and `Property` has been renamed to `flags`. The
387 `type` subnode has retained for backwards compatibility and is populated to the same value as
388 `flags`. However, writes to `type` will not update `flags`.
389 * The `TryCatch` subnode `finallyStmts` has been replaced with a `finally` subnode that holds an
390 explicit `Finally` node. This allows for more accurate attribute assignment.
391 * The `Trait` constructor now has the same form as the `Class` and `Interface` constructors: It
392 takes an array of subnodes. Unlike classes/interfaces, traits can only have a `stmts` subnode.
393 * The `NodeDumper` now prints class/method/property/constant modifiers, as well as the include and
394 use type in a textual representation, instead of only showing the number.
395 * All methods on `PrettyPrinter\Standard` are now protected. Previously most of them were public.
399 * Removed support for running on PHP 5.4. It is however still possible to parse PHP 5.2-5.4 code
400 while running on a newer version.
401 * The deprecated `Comment::setLine()` and `Comment::setText()` methods have been removed.
402 * The deprecated `Name::set()`, `Name::setFirst()` and `Name::setLast()` methods have been removed.
404 Version 2.1.1 (2016-09-16)
405 --------------------------
409 * The pretty printer will now escape all control characters in the range `\x00-\x1F` inside double
410 quoted strings. If no special escape sequence is available, an octal escape will be used.
411 * The quality of the error recovery has been improved. In particular unterminated expressions should
412 be handled more gracefully.
413 * The PHP 7 parser will now generate a parse error for `$var =& new Obj` assignments.
414 * Comments on free-standing code blocks will no be retained as comments on the first statement in
417 Version 2.1.0 (2016-04-19)
418 --------------------------
422 * Properly support `B""` strings (with uppercase `B`) in a number of places.
423 * Fixed reformatting of indented parts in a certain non-standard comment style.
427 * Added `dumpComments` option to node dumper, to enable dumping of comments associated with nodes.
428 * Added `Stmt\Nop` node, that is used to collect comments located at the end of a block or at the
429 end of a file (without a following node with which they could otherwise be associated).
430 * Added `kind` attribute to `Expr\Exit` to distinguish between `exit` and `die`.
431 * Added `kind` attribute to `Scalar\LNumber` to distinguish between decimal, binary, octal and
433 * Added `kind` attribute to `Expr\Array` to distinguish between `array()` and `[]`.
434 * Added `kind` attribute to `Scalar\String` and `Scalar\Encapsed` to distinguish between
435 single-quoted, double-quoted, heredoc and nowdoc string.
436 * Added `docLabel` attribute to `Scalar\String` and `Scalar\Encapsed`, if it is a heredoc or
438 * Added start file offset information to `Comment` nodes.
439 * Added `setReturnType()` method to function and method builders.
440 * Added `-h` and `--help` options to `php-parse` script.
444 * Invalid octal literals now throw a parse error in PHP 7 mode.
445 * The pretty printer takes all the new attributes mentioned in the previous section into account.
446 * The protected `AbstractPrettyPrinter::pComments()` method no longer returns a trailing newline.
447 * The bundled autoloader supports library files being stored in a different directory than
448 `PhpParser` for easier downstream distribution.
452 * The `Comment::setLine()` and `Comment::setText()` methods have been deprecated. Construct new
457 * The internal (but public) method `Scalar\LNumber::parse()` has been removed. A non-internal
458 `LNumber::fromString()` method has been added instead.
460 Version 2.0.1 (2016-02-28)
461 --------------------------
465 * `declare() {}` and `declare();` are not semantically equivalent and will now result in different
466 ASTs. The format case will have an empty `stmts` array, while the latter will set `stmts` to
468 * Magic constants are now supported as semi-reserved keywords.
469 * A shebang line like `#!/usr/bin/env php` is now allowed at the start of a namespaced file.
470 Previously this generated an exception.
471 * The `prettyPrintFile()` method will not strip a trailing `?>` from the raw data that follows a
472 `__halt_compiler()` statement.
473 * The `prettyPrintFile()` method will not strip an opening `<?php` if the file starts with a
474 comment followed by InlineHTML.
476 Version 2.0.0 (2015-12-04)
477 --------------------------
481 * String parts of encapsed strings are now represented using `Scalar\EncapsStringPart` nodes.
482 Previously raw strings were used. This affects the `parts` child of `Scalar\Encaps` and
483 `Expr\ShellExec`. The change has been done to allow assignment of attributes to encapsed string
486 Version 2.0.0-beta1 (2015-10-21)
487 --------------------------------
491 * Fixed issue with too many newlines being stripped at the end of heredoc/nowdoc strings in some
496 * Update group use support to be in line with recent PHP 7.0 builds.
497 * Renamed `php-parse.php` to `php-parse` and registered it as a composer bin.
498 * Use composer PSR-4 autoloader instead of custom autoloader.
499 * Specify phpunit as a dev dependency.
503 * Added `shortArraySyntax` option to pretty printer, to print all arrays using short syntax.
505 Version 2.0.0-alpha1 (2015-07-14)
506 ---------------------------------
508 A more detailed description of backwards incompatible changes can be found in the
509 [upgrading guide](UPGRADE-2.0.md).
513 * Removed support for running on PHP 5.3. It is however still possible to parse PHP 5.2 and PHP 5.3
514 code while running on a newer version.
515 * Removed legacy class name aliases. This includes the old non-namespaced class names and the old
516 names for classes that were renamed for PHP 7 compatibility.
517 * Removed support for legacy node format. All nodes must have a `getSubNodeNames()` method now.
521 * Added support for remaining PHP 7 features that were not present in 1.x:
522 * Group use declarations. These are represented using `Stmt\GroupUse` nodes. Furthermore a `type`
523 attribute was added to `Stmt\UseUse` to handle mixed group use declarations.
524 * Uniform variable syntax.
525 * Generalized yield operator.
526 * Scalar type declarations. These are presented using `'bool'`, `'int'`, `'float'` and `'string'`
527 as the type. The PHP 5 parser also accepts these, however they'll be `Name` instances there.
528 * Unicode escape sequences.
529 * Added `PhpParser\ParserFactory` class, which should be used to create parser instances.
530 * Added `Name::concat()` which concatenates two names.
531 * Added `Name->slice()` which takes a subslice of a name.
535 * `PhpParser\Parser` is now an interface, implemented by `Parser\Php5`, `Parser\Php7` and
536 `Parser\Multiple`. The `Multiple` parser will try multiple parsers, until one succeeds.
537 * Token constants are now defined on `PhpParser\Parser\Tokens` rather than `PhpParser\Parser`.
538 * The `Name->set()`, `Name->append()`, `Name->prepend()` and `Name->setFirst()` methods are
539 deprecated in favor of `Name::concat()` and `Name->slice()`.
540 * The `NodeTraverser` no longer clones nodes by default. The old behavior can be restored by
541 passing `true` to the constructor.
542 * The constructor for `Scalar` nodes no longer has a default value. E.g. `new LNumber()` should now
543 be written as `new LNumber(0)`.
547 **This changelog only includes changes from the 2.0 series. For older changes see the
548 [1.x series changelog](https://github.com/nikic/PHP-Parser/blob/1.x/CHANGELOG.md) and the
549 [0.9 series changelog](https://github.com/nikic/PHP-Parser/blob/0.9/CHANGELOG.md).**