xref: /PHP-Parser/CHANGELOG.md (revision 8eea2304)
1Version 5.3.1 (2024-10-08)
2--------------------------
3
4### Added
5
6* Added support for declaring functions with name `exit` or `die`, to allow their use in stubs.
7
8Version 5.3.0 (2024-09-29)
9--------------------------
10
11### Added
12
13* Added `indent` option to pretty printer, which can be used to specify the indentation to use
14  (defaulting to four spaces). This also allows using tab indentation.
15
16### Fixed
17
18* Resolve names in `PropertyHook`s in the `NameResolver`.
19* Include the trailing semicolon inside `Stmt\GroupUse` nodes, making them consistent with
20  `Stmt\Use_` nodes.
21* Fixed indentation sometimes becoming negative in formatting-preserving pretty printer, resulting
22  in `ValueError`s.
23
24Version 5.2.0 (2024-09-15)
25--------------------------
26
27### Added
28
29* [8.4] Added support for `__PROPERTY__` magic constant, represented using a
30  `Node\Scalar\MagicConst\Property` node.
31* [8.4] Added support for property hooks, which are represented using a new `hooks` subnode on
32  `Node\Stmt\Property` and `Node\Param`, which contains an array of `Node\PropertyHook`.
33* [8.4] Added support for asymmetric visibility modifiers. Property `flags` can now hold the
34  additional bits `Modifiers::PUBLIC_SET`, `Modifiers::PROTECTED_SET` and `Modifiers::PRIVATE_SET`.
35* [8.4] Added support for generalized exit function. For backwards compatibility, exit without
36  argument or a single plain argument continues to use a `Node\Expr\Exit_` node. Otherwise (e.g.
37  if a named argument is used) it will be represented as a plain `Node\Expr\FuncCall`.
38* Added support for passing enum values to various builder methods, like `BuilderFactory::val()`.
39
40### Removed
41
42* Removed support for alternative array syntax `$array{0}` from the PHP 8 parser. It is still
43  supported by the PHP 7 parser. This is necessary in order to support property hooks.
44
45Version 5.1.0 (2024-07-01)
46--------------------------
47
48### Added
49
50* [8.4] Added support for dereferencing `new` expressions without parentheses.
51
52### Fixed
53
54* Fixed redundant parentheses being added when pretty printing ternary expressions.
55
56### Changed
57
58* Made some phpdoc types more precise.
59
60Version 5.0.2 (2024-03-05)
61--------------------------
62
63### Fixed
64
65* Fix handling of indentation on next line after opening PHP tag in formatting-preserving pretty
66printer.
67
68### Changed
69
70* Avoid cyclic references in `Parser` objects. This means that no longer used parser objects are
71  immediately destroyed now, instead of requiring cycle GC.
72* Update `PhpVersion::getNewestSupported()` to report PHP 8.3 instead of PHP 8.2.
73
74Version 5.0.1 (2024-02-21)
75--------------------------
76
77### Changed
78
79* Added check to detect use of PHP-Parser with libraries that define `T_*` compatibility tokens
80  with incorrect type (such as string instead of int). This would lead to `TypeError`s down the
81  line. Now an `Error` will be thrown early to indicate the problem.
82
83Version 5.0.0 (2024-01-07)
84--------------------------
85
86See UPGRADE-5.0 for detailed migration instructions.
87
88### Fixed
89
90* Fixed parent class of `PropertyItem` and `UseItem`.
91
92Version 5.0.0-rc1 (2023-12-20)
93------------------------------
94
95See UPGRADE-5.0 for detailed migration instructions.
96
97### Fixed
98
99* Fixed parsing of empty files.
100
101### Added
102
103* Added support for printing additional attributes (like `kind`) in `NodeDumper`.
104* Added `rawValue` attribute to `InterpolatedStringPart` and heredoc/nowdoc `String_`s, which
105  provides the original, unparsed value. It was previously only available for non-interpolated
106  single/double quoted strings.
107* Added `Stmt\Block` to represent `{}` code blocks. Previously, such code blocks were flattened
108  into the parent statements array. `Stmt\Block` will not be created for structures that are
109  typically used with code blocks, for example `if ($x) { $y; }` will be represented as previously,
110  while `if ($x) { { $x; } }` will have an extra `Stmt\Block` wrapper.
111
112### Changed
113
114* Use visitor to assign comments. This fixes the long-standing issue where comments were assigned
115  to all nodes sharing a starting position. Now only the outer-most node will hold the comments.
116* Don't parse unicode escape sequences when targeting PHP < 7.0.
117* Improve NodeDumper performance for large dumps.
118
119### Removed
120
121* Removed `Stmt\Throw_` node, use `Expr\Throw_` inside `Stmt\Expression` instead.
122* Removed `ParserFactory::create()`.
123
124Version 5.0.0-beta1 (2023-09-17)
125--------------------------------
126
127See UPGRADE-5.0 for detailed migration instructions.
128
129### Added
130
131* Visitors can now be passed directly to the `NodeTraverser` constructor. A separate call to
132  `addVisitor()` is no longer required.
133
134### Changed
135
136* The minimum host PHP version is now PHP 7.4. It is still possible to parse code from older
137  versions. Property types have been added where possible.
138* The `Lexer` no longer accepts options. `Lexer\Emulative` only accepts a `PhpVersion`. The
139  `startLexing()`, `getTokens()` and `handleHaltCompiler()` methods have been removed. Instead,
140  there is a single method `tokenize()` returning the tokens.
141* The `Parser::getLexer()` method has been replaced by `Parser::getTokens()`.
142* Attribute handling has been moved from the lexer to the parser, and is no longer configurable.
143  The comments, startLine, endLine, startTokenPos, endTokenPos, startFilePos, and endFilePos
144  attributes will always be added.
145* The pretty printer now defaults to PHP 7.4 as the target version.
146* The pretty printer now indents heredoc/nowdoc strings if the target version is >= 7.3
147  (flexible heredoc/nowdoc).
148
149### Removed
150
151* The deprecated `Comment::getLine()`, `Comment::getTokenPos()` and `Comment::getFilePos()` methods
152  have been removed. Use `Comment::getStartLine()`, `Comment::getStartTokenPos()` and
153  `Comment::getStartFilePos()` instead.
154
155### Deprecated
156
157* The `Node::getLine()` method has been deprecated. Use `Node::getStartLine()` instead.
158
159Version 5.0.0-alpha3 (2023-06-24)
160---------------------------------
161
162See UPGRADE-5.0 for detailed migration instructions.
163
164### Added
165
166* [PHP 8.3] Added support for typed constants.
167* [PHP 8.3] Added support for readonly anonymous classes.
168* Added support for `NodeVisitor::REPLACE_WITH_NULL`.
169* Added support for CRLF newlines in the pretty printer, using the new `newline` option.
170
171### Changed
172
173* Use PHP 7.1 as the default target version for the pretty printer.
174* Print `else if { }` instead of `else { if { } }`.
175* The `leaveNode()` method on visitors is now invoked in reverse order of `enterNode()`.
176* Moved `NodeTraverser::REMOVE_NODE` etc. to `NodeVisitor::REMOVE_NODE`. The old constants are still
177  available for compatibility.
178* The `Name` subnode `parts` has been replaced by `name`, which stores the name as a string rather
179  than an array of parts separated by namespace separators. The `getParts()` method returns the old
180  representation.
181* No longer accept strings for types in Node constructors. Instead, either an `Identifier`, `Name`
182  or `ComplexType` must be passed.
183* `Comment::getReformattedText()` now normalizes CRLF newlines to LF newlines.
184
185### Fixed
186
187* Don't trim leading whitespace in formatting preserving printer.
188* Treat DEL as a label character in the formatting preserving printer depending on the targeted
189  PHP version.
190* Fix error reporting in emulative lexer without explicitly specified error handler.
191* Gracefully handle non-contiguous array indices in the `Differ`.
192
193Version 5.0.0-alpha2 (2023-03-05)
194---------------------------------
195
196See UPGRADE-5.0 for detailed migration instructions.
197
198### Added
199
200* [PHP 8.3] Added support for dynamic class constant fetch.
201* Added many additional type annotations. PhpStan is now used.
202* Added a fuzzing target for PHP-Fuzzer, which was how a lot of pretty printer bugs were found.
203* Added `isPromoted()`, `isPublic()`, `isProtected()`, `isPrivate()` and `isReadonly()` methods
204  on `Param`.
205* Added support for class constants in trait builder.
206* Added `PrettyPrinter` interface.
207* Added support for formatting preservation when toggling static modifiers.
208* The `php-parse` binary now accepts `-` as the file name, in which case it will read from stdin.
209
210### Fixed
211
212* The pretty printer now uses a more accurate treatment of unary operator precedence, and will only
213  wrap them in parentheses if required. This allowed fixing a number of other precedence related
214  bugs.
215* The pretty printer now respects the precedence of `clone`, `throw` and arrow functions.
216* The pretty printer no longer unconditionally wraps `yield` in parentheses, unless the target
217  version is set to older than PHP 7.0.
218* Fixed formatting preservation for alternative elseif/else syntax.
219* Fixed checks for when it is safe to print strings as heredoc/nowdoc to accommodate flexible
220  doc string semantics.
221* The pretty printer now prints parentheses around new/instanceof operands in all required
222  situations.
223* Similar, differences in allowed expressions on the LHS of `->` and `::` are now taken into account.
224* Fixed various cases where `\r` at the end of a doc string could be incorrectly merged into a CRLF
225  sequence with a following `\n`.
226* `__halt_compiler` is no longer recognized as a semi-reserved keyword, in line with PHP behavior.
227* `<?=` is no longer recognized as a semi-reserved keyword.
228* Fix handling of very large overflowing `\u` escape sequences.
229
230### Removed
231
232* Removed deprecated `Error` constructor taking a line number instead of an attributes array.
233
234Version 5.0.0-alpha1 (2022-09-04)
235---------------------------------
236
237See UPGRADE-5.0 for detailed migration instructions.
238
239### Changed
240
241* PHP 7.1 is now required to run PHP-Parser.
242* Formatting of the standard pretty printer has been adjusted to match PSR-12 more closely.
243* The internal token representation now uses a `PhpParser\Token` class, which is compatible with
244  PHP 8 token representation (`PhpToken`).
245* Destructuring is now always represented using `Expr\List_` nodes, even if it uses `[]` syntax.
246* Renamed a number of node classes, and moved things that were not real expressions/statements
247  outside the `Expr`/`Stmt` hierarchy. Compatibility shims for the old names have been retained.
248
249### Added
250
251* Added `PhpVersion` class, which is accepted in a number of places (e.g. ParserFactory, Parser,
252  Lexer, PrettyPrinter) and gives more precise control over the PHP version being targeted.
253* Added PHP 8 parser though it only differs from the PHP 7 parser in concatenation precedence.
254* Added `Parser::getLexer()` method.
255* Added a `Modifiers` class, as a replacement for `Stmt\Class_::MODIFIER_*`.
256* Added support for returning an array or `REMOVE_NODE` from `NodeVisitor::enterNode()`.
257
258### Removed
259
260* The PHP 5 parser has been removed. The PHP 7 parser has been adjusted to deal with PHP 5 code
261  more gracefully.
262
263Version 4.15.1 (2022-09-04)
264---------------------------
265
266### Fixed
267
268* Fixed formatting preservation when adding *multiple* attributes to a class/method/etc that
269  previously had none. This fixes a regression in the 4.15.0 release.
270
271Version 4.15.0 (2022-09-03)
272---------------------------
273
274### Added
275
276* PHP 8.2: Added support for `true` type.
277* PHP 8.2: Added support for DNF types.
278
279### Fixed
280
281* Support `readonly` as a function name.
282* Added `__serialize` and `__unserialize` to magic method list.
283* Fixed bounds check in `Name::slice()`.
284* Fixed formatting preservation when adding attributes to a class/method/etc that previously had none.
285
286Version 4.14.0 (2022-05-31)
287---------------------------
288
289### Added
290
291* Added support for readonly classes.
292* Added `rawValue` attribute to `LNumber`, `DNumber` and `String_` nodes, which stores the unparsed
293  value of the literal (e.g. `"1_000"` rather than `1000`).
294
295Version 4.13.2 (2021-11-30)
296---------------------------
297
298### Added
299
300* Added builders for enums and enum cases.
301
302### Fixed
303
304* NullsafeMethodCall now extends from CallLike.
305* The `namespacedName` property populated by the `NameResolver` is now declared on relevant nodes,
306  to avoid a dynamic property deprecation warning with PHP 8.2.
307
308Version 4.13.1 (2021-11-03)
309---------------------------
310
311### Fixed
312
313* Support reserved keywords as enum cases.
314* Support array unpacking in constant expression evaluator.
315
316Version 4.13.0 (2021-09-20)
317---------------------------
318
319### Added
320
321* [PHP 8.1] Added support for intersection types using a new `IntersectionType` node. Additionally
322  a `ComplexType` parent class for `NullableType`, `UnionType` and `IntersectionType` has been
323  added.
324* [PHP 8.1] Added support for explicit octal literals.
325* [PHP 8.1] Added support for first-class callables. These are represented using a call whose first
326  argument is a `VariadicPlaceholder`. The representation is intended to be forward-compatible with
327  partial function application, just like the PHP feature itself. Call nodes now extend from
328  `Expr\CallLike`, which provides an `isFirstClassCallable()` method to determine whether a
329  placeholder id present. `getArgs()` can be used to assert that the call is not a first-class
330  callable and returns `Arg[]` rather than `array<Arg|VariadicPlaceholder>`.
331
332### Fixed
333
334* Multiple modifiers for promoted properties are now accepted. In particular this allows something
335  like `public readonly` for promoted properties.
336* Formatting-preserving pretty printing for comments in array literals has been fixed.
337
338Version 4.12.0 (2021-07-21)
339---------------------------
340
341### Added
342
343* [PHP 8.1] Added support for readonly properties (through a new `MODIFIER_READONLY`).
344* [PHP 8.1] Added support for final class constants.
345
346### Fixed
347
348* Fixed compatibility with PHP 8.1. `&` tokens are now canonicalized to the
349  `T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG` and `T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG` tokens
350  used in PHP 8.1. This happens unconditionally, regardless of whether the emulative lexer is used.
351
352Version 4.11.0 (2021-07-03)
353---------------------------
354
355### Added
356
357* `BuilderFactory::args()` now accepts named arguments.
358* `BuilderFactory::attribute()` has been added.
359* An `addAttribute()` method accepting an `Attribute` or `AttributeGroup` has been adde to all
360  builders that accept attributes, such as `Builder\Class_`.
361
362### Fixed
363
364* `NameResolver` now handles enums.
365* `PrettyPrinter` now prints backing enum type.
366* Builder methods for types now property handle `never` type.
367
368Version 4.10.5 (2021-05-03)
369---------------------------
370
371### Added
372
373* [PHP 8.1] Added support for enums. These are represented using the `Stmt\Enum_` and
374  `Stmt\EnumCase` nodes.
375* [PHP 8.1] Added support for never type. This type will now be returned as an `Identifier` rather
376  than `Name`.
377* Added `ClassConst` builder.
378
379### Changed
380
381* Non-UTF-8 code units in strings will now be hex-encoded.
382
383### Fixed
384
385* Fixed precedence of arrow functions.
386
387Version 4.10.4 (2020-12-20)
388---------------------------
389
390### Fixed
391
392* Fixed position information for variable-variables (#741).
393* Fixed position information for traits/interfaces preceded by if statement (#738).
394
395Version 4.10.3 (2020-12-03)
396---------------------------
397
398### Fixed
399
400* Fixed formatting-preserving pretty printing for `"{$x}"`.
401* Ternary expressions are now treated as non-associative in the pretty printer, in order to
402  generate code that is compatible with the parentheses requirement introduced in PHP 8.
403* Removed no longer necessary `error_clear_last()` call in lexer, which may interfere with fatal
404  error handlers if invoked during shutdown.
405
406
407Version 4.10.2 (2020-09-26)
408------------------
409
410### Fixed
411
412* Fixed check for token emulation conflicts with other libraries.
413
414Version 4.10.1 (2020-09-23)
415---------------------------
416
417### Added
418
419* Added support for recovering from a missing semicolon after a property or class constant
420  declaration.
421
422### Fixed
423
424* Fix spurious whitespace in formatting-preserving pretty printer when both removing and adding
425  elements at the start of a list.
426* Fix incorrect case-sensitivity in keyword token emulation.
427
428Version 4.10.0 (2020-09-19)
429---------------------------
430
431### Added
432
433* [PHP 8.0] Added support for attributes. These are represented using a new `AttributeGroup` node
434  containing `Attribute` nodes. A new `attrGroups` subnode is available on all node types that
435  support attributes, i.e. `Stmt\Class_`, `Stmt\Trait_`, `Stmt\Interface_`, `Stmt\Function_`,
436  `Stmt\ClassMethod`, `Stmt\ClassConst`, `Stmt\Property`, `Expr\Closure`, `Expr\ArrowFunction` and
437  `Param`.
438* [PHP 8.0] Added support for nullsafe properties inside interpolated strings, in line with an
439  upstream change.
440
441### Fixed
442
443* Improved compatibility with other libraries that use forward compatibility defines for PHP tokens.
444
445Version 4.9.1 (2020-08-30)
446--------------------------
447
448### Added
449
450* Added support for removing the first element of a list to the formatting-preserving pretty
451  printer.
452
453### Fixed
454
455* Allow member modifiers as part of namespaced names. These were missed when support for other
456  keywords was added.
457
458Version 4.9.0 (2020-08-18)
459--------------------------
460
461### Added
462
463* [PHP 8.0] Added support for named arguments, represented using a new `name` subnode on `Arg`.
464* [PHP 8.0] Added support for static return type, represented like a normal class return type.
465* [PHP 8.0] Added support for throw expression, represented using a new `Expr\Throw_` node. For
466  backwards compatibility reasons, throw expressions in statement context continue to be
467  represented using `Stmt\Throw_`.
468* [PHP 8.0] Added support for keywords as parts of namespaced names.
469
470### Fixed
471
472* Emit parentheses for class constant fetch with complex left-hand-side.
473* Emit parentheses for new/instanceof on complex class expression.
474
475Version 4.8.0 (2020-08-09)
476--------------------------
477
478### Added
479
480* [PHP 8.0] Added support for nullsafe operator, represented using the new
481  `Expr\NullsafePropertyFetch` and `Expr\NullsafeMethodCall` nodes.
482* Added `phpVersion` option to the emulative lexer, which allows controlling the target version to
483  emulate (defaults to the latest available, currently PHP 8.0). This is useful to parse code that
484  uses reserved keywords from newer PHP versions as identifiers.
485
486Version 4.7.0 (2020-07-25)
487--------------------------
488
489### Added
490
491* Add `ParentConnectingVisitor` and `NodeConnectingVisitor` classes.
492* [PHP 8.0] Added support for match expressions. These are represented using a new `Expr\Match_`
493  containing `MatchArm`s.
494* [PHP 8.0] Added support for trailing comma in closure use lists.
495
496### Fixed
497
498* Fixed missing error for unterminated comment with trailing newline (#688).
499* Compatibility with PHP 8.0 has been restored: Namespaced names are now always represented by
500  `T_NAME_*` tokens, using emulationg on older PHP versions. Full support for reserved keywords
501  in namespaced names is not yet present.
502
503Version 4.6.0 (2020-07-02)
504--------------------------
505
506### Added
507
508* [PHP 8.0] Added support for trailing commas in parameter lists.
509* [PHP 8.0] Added support for constructor promotion. The parameter visibility is stored in
510  `Node\Param::$flags`.
511
512### Fixed
513
514* Comment tokens now always follow the PHP 8 interpretation, and do not include trailing
515  whitespace.
516* As a result of the previous change, some whitespace issues when inserting a statement into a
517  method containing only a comment, and using the formatting-preserving pretty printer, have been
518  resolved.
519
520Version 4.5.0 (2020-06-03)
521--------------------------
522
523### Added
524
525* [PHP 8.0] Added support for the mixed type. This means `mixed` types are now parsed as an
526  `Identifier` rather than a `Name`.
527* [PHP 8.0] Added support for catching without capturing the exception. This means that
528  `Catch_::$var` may now be null.
529
530Version 4.4.0 (2020-04-10)
531--------------------------
532
533### Added
534
535* Added support for passing union types in builders.
536* Added end line, token position and file position information for comments.
537* Added `getProperty()` method to `ClassLike` nodes.
538
539### Fixed
540
541* Fixed generation of invalid code when using the formatting preserving pretty printer, and
542  inserting code next to certain nop statements. The formatting is still ugly though.
543* `getDocComment()` no longer requires that the very last comment before a node be a doc comment.
544  There may not be non-doc comments between the doc comment and the declaration.
545* Allowed arbitrary expressions in `isset()` and `list()`, rather than just variables.
546  In particular, this allows `isset(($x))`, which is legal PHP code.
547* [PHP 8.0] Add support for [variable syntax tweaks RFC](https://wiki.php.net/rfc/variable_syntax_tweaks).
548
549Version 4.3.0 (2019-11-08)
550--------------------------
551
552### Added
553
554* [PHP 8.0] Added support for union types using a new `UnionType` node.
555
556Version 4.2.5 (2019-10-25)
557--------------------------
558
559### Changed
560
561* Tests and documentation are no longer included in source archives. They can still be accessed
562  by cloning the repository.
563* php-yacc is now used to generate the parser. This has no impact on users of the library.
564
565Version 4.2.4 (2019-09-01)
566--------------------------
567
568### Added
569
570* Added getProperties(), getConstants() and getTraitUses() to ClassLike. (#629, #630)
571
572### Fixed
573
574* Fixed flexible heredoc emulation to check for digits after the end label. This synchronizes
575  behavior with the upcoming PHP 7.3.10 release.
576
577Version 4.2.3 (2019-08-12)
578--------------------------
579
580### Added
581
582* [PHP 7.4] Add support for numeric literal separators. (#615)
583
584### Fixed
585
586* Fixed resolution of return types for arrow functions. (#613)
587* Fixed compatibility with PHP 7.4.
588
589Version 4.2.2 (2019-05-25)
590--------------------------
591
592### Added
593
594* [PHP 7.4] Add support for arrow functions using a new `Expr\ArrowFunction` node. (#602)
595* [PHP 7.4] Add support for array spreads, using a new `unpack` subnode on `ArrayItem`. (#609)
596* Added support for inserting into empty list nodes in the formatting preserving pretty printer.
597
598### Changed
599
600* `php-parse` will now print messages to stderr, so that stdout only contains the actual result of
601  the operation (such as a JSON dump). (#605)
602
603### Fixed
604
605* Fixed attribute assignment for zero-length nop statements, and a related assertion failure in
606  the formatting-preserving pretty printer. (#589)
607
608Version 4.2.1 (2019-02-16)
609--------------------------
610
611### Added
612
613* [PHP 7.4] Add support for `??=` operator through a new `AssignOp\Coalesce` node. (#575)
614
615Version 4.2.0 (2019-01-12)
616--------------------------
617
618### Added
619
620* [PHP 7.4] Add support for typed properties through a new `type` subnode of `Stmt\Property`.
621  Additionally `Builder\Property` now has a `setType()` method. (#567)
622* Add `kind` attribute to `Cast\Double_`, which allows to distinguish between `(float)`,
623  `(double)` and `(real)`. The form of the cast will be preserved by the pretty printer. (#565)
624
625### Fixed
626
627* Remove assertion when pretty printing anonymous class with a name (#554).
628
629Version 4.1.1 (2018-12-26)
630--------------------------
631
632### Fixed
633
634* Fix "undefined offset" notice when parsing specific malformed code (#551).
635
636### Added
637
638* Support error recovery for missing return type (`function foo() : {}`) (#544).
639
640Version 4.1.0 (2018-10-10)
641--------------------------
642
643### Added
644
645* Added support for PHP 7.3 flexible heredoc/nowdoc strings, completing support for PHP 7.3. There
646  are two caveats for this feature:
647   * In some rare, pathological cases flexible heredoc/nowdoc strings change the interpretation of
648     existing doc strings. PHP-Parser will now use the new interpretation.
649   * Flexible heredoc/nowdoc strings require special support from the lexer. Because this is not
650     available on PHP versions before 7.3, support has to be emulated. This emulation is not perfect
651     and some cases which we do not expect to occur in practice (such as flexible doc strings being
652     nested within each other through abuse of variable-variable interpolation syntax) may not be
653     recognized correctly.
654* Added `DONT_TRAVERSE_CURRENT_AND_CHILDREN` to `NodeTraverser` to skip both traversal of child
655  nodes, and prevent subsequent visitors from visiting the current node.
656
657Version 4.0.4 (2018-09-18)
658--------------------------
659
660### Added
661
662* The following methods have been added to `BuilderFactory`:
663  * `useTrait()` (fluent builder)
664  * `traitUseAdaptation()` (fluent builder)
665  * `useFunction()` (fluent builder)
666  * `useConst()` (fluent builder)
667  * `var()`
668  * `propertyFetch()`
669
670### Deprecated
671
672* `Builder\Param::setTypeHint()` has been deprecated in favor of the newly introduced
673  `Builder\Param::setType()`.
674
675Version 4.0.3 (2018-07-15)
676--------------------------
677
678### Fixed
679
680* Fixed possible undefined offset notice in formatting-preserving printer. (#513)
681
682### Added
683
684* Improved error recovery inside arrays.
685* Preserve trailing comment inside classes. **Note:** This change is possibly BC breaking if your
686  code validates that classes can only contain certain statement types. After this change, classes
687  can also contain Nop statements, while this was not previously possible. (#509)
688
689Version 4.0.2 (2018-06-03)
690--------------------------
691
692### Added
693
694* Improved error recovery inside classes.
695* Support error recovery for `foreach` without `as`.
696* Support error recovery for parameters without variable (`function (Type ) {}`).
697* Support error recovery for functions without body (`function ($foo)`).
698
699Version 4.0.1 (2018-03-25)
700--------------------------
701
702### Added
703
704* [PHP 7.3] Added support for trailing commas in function calls.
705* [PHP 7.3] Added support for by-reference array destructuring.
706* Added checks to node traverser to prevent replacing a statement with an expression or vice versa.
707  This should prevent common mistakes in the implementation of node visitors.
708* Added the following methods to `BuilderFactory`, to simplify creation of expressions:
709  * `funcCall()`
710  * `methodCall()`
711  * `staticCall()`
712  * `new()`
713  * `constFetch()`
714  * `classConstFetch()`
715
716Version 4.0.0 (2018-02-28)
717--------------------------
718
719* No significant code changes since the beta 1 release.
720
721Version 4.0.0-beta1 (2018-01-27)
722--------------------------------
723
724### Fixed
725
726* In formatting-preserving pretty printer: Fixed indentation when inserting into lists. (#466)
727
728### Added
729
730* In formatting-preserving pretty printer: Improved formatting of elements inserted into multi-line
731  arrays.
732
733### Removed
734
735* The `Autoloader` class has been removed. It is now required to use the Composer autoloader.
736
737Version 4.0.0-alpha3 (2017-12-26)
738---------------------------------
739
740### Fixed
741
742* In the formatting-preserving pretty printer:
743  * Fixed comment indentation.
744  * Fixed handling of inline HTML in the fallback case.
745  * Fixed insertion into list nodes that require creation of a code block.
746
747### Added
748
749* Added support for inserting at the start of list nodes in formatting-preserving pretty printer.
750
751Version 4.0.0-alpha2 (2017-11-10)
752---------------------------------
753
754### Added
755
756* In the formatting-preserving pretty printer:
757  * Added support for changing modifiers.
758  * Added support for anonymous classes.
759  * Added support for removing from list nodes.
760  * Improved support for changing comments.
761* Added start token offsets to comments.
762
763Version 4.0.0-alpha1 (2017-10-18)
764---------------------------------
765
766### Added
767
768* Added experimental support for format-preserving pretty-printing. In this mode formatting will be
769  preserved for parts of the code which have not been modified.
770* Added `replaceNodes` option to `NameResolver`, defaulting to true. If this option is disabled,
771  resolved names will be added as `resolvedName` attributes, instead of replacing the original
772  names.
773* Added `NodeFinder` class, which can be used to find nodes based on a callback or class name. This
774  is a utility to avoid custom node visitor implementations for simple search operations.
775* Added `ClassMethod::isMagic()` method.
776* Added `BuilderFactory` methods: `val()` method for creating an AST for a simple value, `concat()`
777  for creating concatenation trees, `args()` for preparing function arguments.
778* Added `NameContext` class, which encapsulates the `NameResolver` logic independently of the actual
779  AST traversal. This facilitates use in other context, such as class names in doc comments.
780  Additionally it provides an API for getting the shortest representation of a name.
781* Added `Node::setAttributes()` method.
782* Added `JsonDecoder`. This allows conversion JSON back into an AST.
783* Added `Name` methods `toLowerString()` and `isSpecialClassName()`.
784* Added `Identifier` and `VarLikeIdentifier` nodes, which are used in place of simple strings in
785  many places.
786* Added `getComments()`, `getStartLine()`, `getEndLine()`, `getStartTokenPos()`, `getEndTokenPos()`,
787  `getStartFilePos()` and `getEndFilePos()` methods to `Node`. These provide a more obvious access
788  point for the already existing attributes of the same name.
789* Added `ConstExprEvaluator` to evaluate constant expressions to PHP values.
790* Added `Expr\BinaryOp::getOperatorSigil()`, returning `+` for `Expr\BinaryOp\Plus`, etc.
791
792### Changed
793
794* Many subnodes that previously held simple strings now use `Identifier` (or `VarLikeIdentifier`)
795  nodes. Please see the UPGRADE-4.0 file for an exhaustive list of affected nodes and some notes on
796  possible impact.
797* Expression statements (`expr;`) are now represented using a `Stmt\Expression` node. Previously
798  these statements were directly represented as their constituent expression.
799* The `name` subnode of `Param` has been renamed to `var` and now contains a `Variable` rather than
800  a plain string.
801* The `name` subnode of `StaticVar` has been renamed to `var` and now contains a `Variable` rather
802  than a plain string.
803* The `var` subnode of `ClosureUse` now contains a `Variable` rather than a plain string.
804* The `var` subnode of `Catch` now contains a `Variable` rather than a plain string.
805* The `alias` subnode of `UseUse` is now `null` if no explicit alias is given. As such,
806  `use Foo\Bar` and `use Foo\Bar as Bar` are now represented differently. The `getAlias()` method
807  can be used to get the effective alias, even if it is not explicitly given.
808
809### Removed
810
811* Support for running on PHP 5 and HHVM has been removed. You can however still parse code of old
812  PHP versions (such as PHP 5.2), while running on PHP 7.
813* Removed `type` subnode on `Class`, `ClassMethod` and `Property` nodes. Use `flags` instead.
814* The `ClassConst::isStatic()` method has been removed. Constants cannot have a static modifier.
815* The `NodeTraverser` no longer accepts `false` as a return value from a `leaveNode()` method.
816  `NodeTraverser::REMOVE_NODE` should be returned instead.
817* The `Node::setLine()` method has been removed. If you really need to, you can use `setAttribute()`
818  instead.
819* The misspelled `Class_::VISIBILITY_MODIFER_MASK` constant has been dropped in favor of
820  `Class_::VISIBILITY_MODIFIER_MASK`.
821* The XML serializer has been removed. As such, the classes `Serializer\XML`, and
822  `Unserializer\XML`, as well as the interfaces `Serializer` and `Unserializer` no longer exist.
823* The `BuilderAbstract` class has been removed. It's functionality is moved into `BuilderHelpers`.
824  However, this is an internal class and should not be used directly.
825
826Version 3.1.5 (2018-02-28)
827--------------------------
828
829### Fixed
830
831* Fixed duplicate comment assignment in switch statements. (#469)
832* Improve compatibility with PHP-Scoper. (#477)
833
834Version 3.1.4 (2018-01-25)
835--------------------------
836
837### Fixed
838
839* Fixed pretty printing of `-(-$x)` and `+(+$x)`. (#459)
840
841Version 3.1.3 (2017-12-26)
842--------------------------
843
844### Fixed
845
846* Improve compatibility with php-scoper, by supporting prefixed namespaces in
847  `NodeAbstract::getType()`.
848
849Version 3.1.2 (2017-11-04)
850--------------------------
851
852### Fixed
853
854* Comments on empty blocks are now preserved on a `Stmt\Nop` node. (#382)
855
856### Added
857
858* Added `kind` attribute for `Stmt\Namespace_` node, which is one of `KIND_SEMICOLON` or
859  `KIND_BRACED`. (#417)
860* Added `setDocComment()` method to namespace builder. (#437)
861
862Version 3.1.1 (2017-09-02)
863--------------------------
864
865### Fixed
866
867* Fixed syntax error on comment after brace-style namespace declaration. (#412)
868* Added support for TraitUse statements in trait builder. (#413)
869
870Version 3.1.0 (2017-07-28)
871--------------------------
872
873### Added
874
875* [PHP 7.2] Added support for trailing comma in group use statements.
876* [PHP 7.2] Added support for `object` type. This means `object` types will now be represented as a
877  builtin type (a simple `"object"` string), rather than a class `Name`.
878
879### Fixed
880
881* Floating-point numbers are now printed correctly if the LC_NUMERIC locale uses a comma as decimal
882  separator.
883
884### Changed
885
886* `Name::$parts` is no longer deprecated.
887
888Version 3.0.6 (2017-06-28)
889--------------------------
890
891### Fixed
892
893* Fixed the spelling of `Class_::VISIBILITY_MODIFIER_MASK`. The previous spelling of
894  `Class_::VISIBILITY_MODIFER_MASK` is preserved for backwards compatibility.
895* The pretty printing will now preserve comments inside array literals and function calls by
896  printing the array items / function arguments on separate lines. Array literals and functions that
897  do not contain comments are not affected.
898
899### Added
900
901* Added `Builder\Param::makeVariadic()`.
902
903### Deprecated
904
905* The `Node::setLine()` method has been deprecated.
906
907Version 3.0.5 (2017-03-05)
908--------------------------
909
910### Fixed
911
912* Name resolution of `NullableType`s is now performed earlier, so that a fully resolved signature is
913  available when a function is entered. (#360)
914* `Error` nodes are now considered empty, while previously they extended until the token where the
915  error occurred. This made some nodes larger than expected. (#359)
916* Fixed notices being thrown during error recovery in some situations. (#362)
917
918Version 3.0.4 (2017-02-10)
919--------------------------
920
921### Fixed
922
923* Fixed some extensibility issues in pretty printer (`pUseType()` is now public and `pPrec()` calls
924  into `p()`, instead of directly dispatching to the type-specific printing method).
925* Fixed notice in `bin/php-parse` script.
926
927### Added
928
929* Error recovery from missing semicolons is now supported in more cases.
930* Error recovery from trailing commas in positions where PHP does not support them is now supported.
931
932Version 3.0.3 (2017-02-03)
933--------------------------
934
935### Fixed
936
937* In `"$foo[0]"` the `0` is now parsed as an `LNumber` rather than `String`. (#325)
938* Ensure integers and floats are always pretty printed preserving semantics, even if the particular
939  value can only be manually constructed.
940* Throw a `LogicException` when trying to pretty-print an `Error` node. Previously this resulted in
941  an undefined method exception or fatal error.
942
943### Added
944
945* [PHP 7.1] Added support for negative interpolated offsets: `"$foo[-1]"`
946* Added `preserveOriginalNames` option to `NameResolver`. If this option is enabled, an
947  `originalName` attribute, containing the unresolved name, will be added to each resolved name.
948* Added `php-parse --with-positions` option, which dumps nodes with position information.
949
950### Deprecated
951
952* The XML serializer has been deprecated. In particular, the classes `Serializer\XML`,
953  `Unserializer\XML`, as well as the interfaces `Serializer` and `Unserializer` are deprecated.
954
955Version 3.0.2 (2016-12-06)
956--------------------------
957
958### Fixed
959
960* Fixed name resolution of nullable types. (#324)
961* Fixed pretty-printing of nullable types.
962
963Version 3.0.1 (2016-12-01)
964--------------------------
965
966### Fixed
967
968* Fixed handling of nested `list()`s: If the nested list was unkeyed, it was directly included in
969  the list items. If it was keyed, it was wrapped in `ArrayItem`. Now nested `List_` nodes are
970  always wrapped in `ArrayItem`s. (#321)
971
972Version 3.0.0 (2016-11-30)
973--------------------------
974
975### Added
976
977* Added support for dumping node positions in the NodeDumper through the `dumpPositions` option.
978* Added error recovery support for `$`, `new`, `Foo::`.
979
980Version 3.0.0-beta2 (2016-10-29)
981--------------------------------
982
983This release primarily improves our support for error recovery.
984
985### Added
986
987* Added `Node::setDocComment()` method.
988* Added `Error::getMessageWithColumnInfo()` method.
989* Added support for recovery from lexer errors.
990* Added support for recovering from "special" errors (i.e. non-syntax parse errors).
991* Added precise location information for lexer errors.
992* Added `ErrorHandler` interface, and `ErrorHandler\Throwing` and `ErrorHandler\Collecting` as
993  specific implementations. These provide a general mechanism for handling error recovery.
994* Added optional `ErrorHandler` argument to `Parser::parse()`, `Lexer::startLexing()` and
995  `NameResolver::__construct()`.
996* The `NameResolver` now adds a `namespacedName` attribute on name nodes that cannot be statically
997  resolved (unqualified unaliased function or constant names in namespaces).
998
999### Fixed
1000
1001* Fixed attribute assignment for `GroupUse` prefix and variables in interpolated strings.
1002
1003### Changed
1004
1005* The constants on `NameTraverserInterface` have been moved into the `NameTraverser` class.
1006* Due to the error handling changes, the `Parser` interface and `Lexer` API have changed.
1007* The emulative lexer now directly postprocesses tokens, instead of using `~__EMU__~` sequences.
1008  This changes the protected API of the lexer.
1009* The `Name::slice()` method now returns `null` for empty slices, previously `new Name([])` was
1010  used. `Name::concat()` now also supports concatenation with `null`.
1011
1012### Removed
1013
1014* Removed `Name::append()` and `Name::prepend()`. These mutable methods have been superseded by
1015  the immutable `Name::concat()`.
1016* Removed `Error::getRawLine()` and `Error::setRawLine()`. These methods have been superseded by
1017  `Error::getStartLine()` and `Error::setStartLine()`.
1018* Removed support for node cloning in the `NodeTraverser`.
1019* Removed `$separator` argument from `Name::toString()`.
1020* Removed `throw_on_error` parser option and `Parser::getErrors()` method. Use the `ErrorHandler`
1021  mechanism instead.
1022
1023Version 3.0.0-beta1 (2016-09-16)
1024--------------------------------
1025
1026### Added
1027
1028* [7.1] Function/method and parameter builders now support PHP 7.1 type hints (void, iterable and
1029  nullable types).
1030* Nodes and Comments now implement `JsonSerializable`. The node kind is stored in a `nodeType`
1031  property.
1032* The `InlineHTML` node now has an `hasLeadingNewline` attribute, that specifies whether the
1033  preceding closing tag contained a newline. The pretty printer honors this attribute.
1034* Partial parsing of `$obj->` (with missing property name) is now supported in error recovery mode.
1035* The error recovery mode is now exposed in the `php-parse` script through the `--with-recovery`
1036  or `-r` flags.
1037
1038The following changes are also part of PHP-Parser 2.1.1:
1039
1040* The PHP 7 parser will now generate a parse error for `$var =& new Obj` assignments.
1041* Comments on free-standing code blocks will now be retained as comments on the first statement in
1042  the code block.
1043
1044Version 3.0.0-alpha1 (2016-07-25)
1045---------------------------------
1046
1047### Added
1048
1049* [7.1] Added support for `void` and `iterable` types. These will now be represented as strings
1050  (instead of `Name` instances) similar to other builtin types.
1051* [7.1] Added support for class constant visibility. The `ClassConst` node now has a `flags` subnode
1052  holding the visibility modifier, as well as `isPublic()`, `isProtected()` and `isPrivate()`
1053  methods. The constructor changed to accept the additional subnode.
1054* [7.1] Added support for nullable types. These are represented using a new `NullableType` node
1055  with a single `type` subnode.
1056* [7.1] Added support for short array destructuring syntax. This means that `Array` nodes may now
1057  appear as the left-hand-side of assignments and foreach value targets. Additionally the array
1058  items may now contain `null` values if elements are skipped.
1059* [7.1] Added support for keys in list() destructuring. The `List` subnode `vars` has been renamed
1060  to `items` and now contains `ArrayItem`s instead of plain variables.
1061* [7.1] Added support for multi-catch. The `Catch` subnode `type` has been renamed to `types` and
1062  is now an array of `Name`s.
1063* `Name::slice()` now supports lengths and negative offsets. This brings it in line with
1064  `array_slice()` functionality.
1065
1066### Changed
1067
1068Due to PHP 7.1 support additions described above, the node structure changed as follows:
1069
1070* `void` and `iterable` types are now stored as strings if the PHP 7 parser is used.
1071* The `ClassConst` constructor changed to accept an additional `flags` subnode.
1072* The `Array` subnode `items` may now contain `null` elements (destructuring).
1073* The `List` subnode `vars` has been renamed to `items` and now contains `ArrayItem`s instead of
1074  plain variables.
1075* The `Catch` subnode `type` has been renamed to `types` and is now an array of `Name`s.
1076
1077Additionally the following changes were made:
1078
1079* The `type` subnode on `Class`, `ClassMethod` and `Property` has been renamed to `flags`. The
1080  `type` subnode has retained for backwards compatibility and is populated to the same value as
1081  `flags`. However, writes to `type` will not update `flags`.
1082* The `TryCatch` subnode `finallyStmts` has been replaced with a `finally` subnode that holds an
1083  explicit `Finally` node. This allows for more accurate attribute assignment.
1084* The `Trait` constructor now has the same form as the `Class` and `Interface` constructors: It
1085  takes an array of subnodes. Unlike classes/interfaces, traits can only have a `stmts` subnode.
1086* The `NodeDumper` now prints class/method/property/constant modifiers, as well as the include and
1087  use type in a textual representation, instead of only showing the number.
1088* All methods on `PrettyPrinter\Standard` are now protected. Previously most of them were public.
1089
1090### Removed
1091
1092* Removed support for running on PHP 5.4. It is however still possible to parse PHP 5.2-5.4 code
1093  while running on a newer version.
1094* The deprecated `Comment::setLine()` and `Comment::setText()` methods have been removed.
1095* The deprecated `Name::set()`, `Name::setFirst()` and `Name::setLast()` methods have been removed.
1096
1097Version 2.1.1 (2016-09-16)
1098--------------------------
1099
1100### Changed
1101
1102* The pretty printer will now escape all control characters in the range `\x00-\x1F` inside double
1103  quoted strings. If no special escape sequence is available, an octal escape will be used.
1104* The quality of the error recovery has been improved. In particular unterminated expressions should
1105  be handled more gracefully.
1106* The PHP 7 parser will now generate a parse error for `$var =& new Obj` assignments.
1107* Comments on free-standing code blocks will no be retained as comments on the first statement in
1108  the code block.
1109
1110Version 2.1.0 (2016-04-19)
1111--------------------------
1112
1113### Fixed
1114
1115* Properly support `B""` strings (with uppercase `B`) in a number of places.
1116* Fixed reformatting of indented parts in a certain non-standard comment style.
1117
1118### Added
1119
1120* Added `dumpComments` option to node dumper, to enable dumping of comments associated with nodes.
1121* Added `Stmt\Nop` node, that is used to collect comments located at the end of a block or at the
1122  end of a file (without a following node with which they could otherwise be associated).
1123* Added `kind` attribute to `Expr\Exit` to distinguish between `exit` and `die`.
1124* Added `kind` attribute to `Scalar\LNumber` to distinguish between decimal, binary, octal and
1125  hexadecimal numbers.
1126* Added `kind` attribute to `Expr\Array` to distinguish between `array()` and `[]`.
1127* Added `kind` attribute to `Scalar\String` and `Scalar\Encapsed` to distinguish between
1128  single-quoted, double-quoted, heredoc and nowdoc string.
1129* Added `docLabel` attribute to `Scalar\String` and `Scalar\Encapsed`, if it is a heredoc or
1130  nowdoc string.
1131* Added start file offset information to `Comment` nodes.
1132* Added `setReturnType()` method to function and method builders.
1133* Added `-h` and `--help` options to `php-parse` script.
1134
1135### Changed
1136
1137* Invalid octal literals now throw a parse error in PHP 7 mode.
1138* The pretty printer takes all the new attributes mentioned in the previous section into account.
1139* The protected `AbstractPrettyPrinter::pComments()` method no longer returns a trailing newline.
1140* The bundled autoloader supports library files being stored in a different directory than
1141  `PhpParser` for easier downstream distribution.
1142
1143### Deprecated
1144
1145* The `Comment::setLine()` and `Comment::setText()` methods have been deprecated. Construct new
1146  objects instead.
1147
1148### Removed
1149
1150* The internal (but public) method `Scalar\LNumber::parse()` has been removed. A non-internal
1151  `LNumber::fromString()` method has been added instead.
1152
1153Version 2.0.1 (2016-02-28)
1154--------------------------
1155
1156### Fixed
1157
1158* `declare() {}` and `declare();` are not semantically equivalent and will now result in different
1159  ASTs. The format case will have an empty `stmts` array, while the latter will set `stmts` to
1160  `null`.
1161* Magic constants are now supported as semi-reserved keywords.
1162* A shebang line like `#!/usr/bin/env php` is now allowed at the start of a namespaced file.
1163  Previously this generated an exception.
1164* The `prettyPrintFile()` method will not strip a trailing `?>` from the raw data that follows a
1165  `__halt_compiler()` statement.
1166* The `prettyPrintFile()` method will not strip an opening `<?php` if the file starts with a
1167  comment followed by InlineHTML.
1168
1169Version 2.0.0 (2015-12-04)
1170--------------------------
1171
1172### Changed
1173
1174* String parts of encapsed strings are now represented using `Scalar\EncapsStringPart` nodes.
1175  Previously raw strings were used. This affects the `parts` child of `Scalar\Encaps` and
1176  `Expr\ShellExec`. The change has been done to allow assignment of attributes to encapsed string
1177  parts.
1178
1179Version 2.0.0-beta1 (2015-10-21)
1180--------------------------------
1181
1182### Fixed
1183
1184* Fixed issue with too many newlines being stripped at the end of heredoc/nowdoc strings in some
1185  cases. (#227)
1186
1187### Changed
1188
1189* Update group use support to be in line with recent PHP 7.0 builds.
1190* Renamed `php-parse.php` to `php-parse` and registered it as a composer bin.
1191* Use composer PSR-4 autoloader instead of custom autoloader.
1192* Specify phpunit as a dev dependency.
1193
1194### Added
1195
1196* Added `shortArraySyntax` option to pretty printer, to print all arrays using short syntax.
1197
1198Version 2.0.0-alpha1 (2015-07-14)
1199---------------------------------
1200
1201A more detailed description of backwards incompatible changes can be found in the
1202[upgrading guide](UPGRADE-2.0.md).
1203
1204### Removed
1205
1206* Removed support for running on PHP 5.3. It is however still possible to parse PHP 5.2 and PHP 5.3
1207  code while running on a newer version.
1208* Removed legacy class name aliases. This includes the old non-namespaced class names and the old
1209  names for classes that were renamed for PHP 7 compatibility.
1210* Removed support for legacy node format. All nodes must have a `getSubNodeNames()` method now.
1211
1212### Added
1213
1214* Added support for remaining PHP 7 features that were not present in 1.x:
1215  * Group use declarations. These are represented using `Stmt\GroupUse` nodes. Furthermore a `type`
1216    attribute was added to `Stmt\UseUse` to handle mixed group use declarations.
1217  * Uniform variable syntax.
1218  * Generalized yield operator.
1219  * Scalar type declarations. These are presented using `'bool'`, `'int'`, `'float'` and `'string'`
1220    as the type. The PHP 5 parser also accepts these, however they'll be `Name` instances there.
1221  * Unicode escape sequences.
1222* Added `PhpParser\ParserFactory` class, which should be used to create parser instances.
1223* Added `Name::concat()` which concatenates two names.
1224* Added `Name->slice()` which takes a subslice of a name.
1225
1226### Changed
1227
1228* `PhpParser\Parser` is now an interface, implemented by `Parser\Php5`, `Parser\Php7` and
1229  `Parser\Multiple`. The `Multiple` parser will try multiple parsers, until one succeeds.
1230* Token constants are now defined on `PhpParser\Parser\Tokens` rather than `PhpParser\Parser`.
1231* The `Name->set()`, `Name->append()`, `Name->prepend()` and `Name->setFirst()` methods are
1232  deprecated in favor of `Name::concat()` and `Name->slice()`.
1233* The `NodeTraverser` no longer clones nodes by default. The old behavior can be restored by
1234  passing `true` to the constructor.
1235* The constructor for `Scalar` nodes no longer has a default value. E.g. `new LNumber()` should now
1236  be written as `new LNumber(0)`.
1237
1238---
1239
1240**This changelog only includes changes from the 2.0 series. For older changes see the
1241[1.x series changelog](https://github.com/nikic/PHP-Parser/blob/1.x/CHANGELOG.md) and the
1242[0.9 series changelog](https://github.com/nikic/PHP-Parser/blob/0.9/CHANGELOG.md).**
1243