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