Skip to content

Commit

Permalink
Document phpVersion effect on pretty printer
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Sep 17, 2023
1 parent 5a7753a commit 3c52ea9
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions doc/component/Pretty_printing.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3c52ea9

Please sign in to comment.