The pretty printer that comes with PHP is designed to pretty print an AST-representation of a PHP-program according to a set of rules. It is not designed to return the exact same document that was parsed.

The following rules are used for pretty printing:

  • Expressions are printed on a single line.
  • Indentation is done for all nestings of statements, 2 spaces per nesting.
  • Control structures have a space between the keyword and the opening parenthesis.
  • Curly braces are printed if they appear in the source.
  • The opening curly brace of a statement is printed on the same line as the control structure.
  • The closing curly brace of a statement is printed on its own line, on the start of the indentation.
  • Function calls do not have a space between the name and the opening parenthesis.
  • Parameters to a function are separated by a space.
  • The include_* and require_* expressions do not have parentheses around their argument.

Notice that most of the rules follow the PEAR coding-standard.

Revision: r1.2 - 11 Nov 2007 - 13:58 - EricBouwers
PHP > WebLeftBar > PhpFrontDocumentation > PrettyPrintRules
Copyright © 1999-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback