mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-17 15:18:17 +01:00
Document phpVersion effect on pretty printer
This commit is contained in:
parent
5a7753a930
commit
3c52ea9b6d
@ -31,17 +31,29 @@ expression.
|
||||
Customizing the formatting
|
||||
--------------------------
|
||||
|
||||
The pretty printer respects a number of `kind` attributes used by some notes (e.g., whether an
|
||||
The pretty printer respects a number of `kind` attributes used by some nodes (e.g., whether an
|
||||
integer should be printed as decimal, hexadecimal, etc). Additionally, it supports three options:
|
||||
|
||||
* `phpVersion` (defaults to 7.1) allows opting into formatting that is not supported by older PHP
|
||||
* `phpVersion` (defaults to 7.4) allows opting into formatting that is not supported by older PHP
|
||||
versions.
|
||||
* `newline` (defaults to `"\n"`) can be set to `"\r\n"` in order to produce Windows newlines.
|
||||
* `shortArraySyntax` determines the used array syntax if the `kind` attribute is not set. This is
|
||||
a legacy option, and `phpVersion` should be used to control this behavior instead.
|
||||
|
||||
However, the default pretty printer does not provide any functionality for fine-grained
|
||||
customization of code formatting.
|
||||
The behaviors controlled by `phpVersion` (defaults to PHP 7.4) are:
|
||||
|
||||
* For PHP >= 7.0, short array syntax `[]` will be used by default. This does not affect nodes that
|
||||
specify an explicit array syntax using the `kind` attribute.
|
||||
* For PHP >= 7.0, parentheses around `yield` expressions will only be printed when necessary.
|
||||
* For PHP >= 7.1, the short array syntax `[]` will be used for destructuring by default (instead of
|
||||
`list()`). This does not affect nodes that specify and explicit syntax using the `kind` attribute.
|
||||
* For PHP >= 7.3, a newline is no longer forced after heredoc/nowdoc strings, as the requirement
|
||||
for this has been removed with the introduction of flexible heredoc/nowdoc strings.
|
||||
* For PHP >= 7.3, heredoc/nowdoc strings are indented just like regular code. This was allowed with
|
||||
the introduction of flexible heredoc/nowdoc strings.
|
||||
|
||||
The default pretty printer does not provide functionality for fine-grained customization of code
|
||||
formatting.
|
||||
|
||||
If you want to make minor changes to the formatting, the easiest way is to extend the pretty printer
|
||||
and override the methods responsible for the node types you are interested in.
|
||||
|
Loading…
x
Reference in New Issue
Block a user