Copied!
CloneableInstantiable
Methods
public PhpParser\PrettyPrinterAbstract::__construct(array $options = [])
 

Creates a pretty printer instance using the given options.

Supported options:

  • PhpVersion $phpVersion: The PHP version to target (default to PHP 7.4). This option controls compatibility of the generated code with older PHP versions in cases where a simple stylistic choice exists (e.g. array() vs []). It is safe to pretty-print an AST for a newer PHP version while specifying an older target (but the result will of course not be compatible with the older version in that case).
  • string $newline: The newline style to use. Should be "\n" (default) or "\r\n".
  • string $indent: The indentation to use. Should either be all spaces or a single tab. Defaults to four spaces (" ").
  • bool $shortArraySyntax: Whether to use [] instead of array() as the default array syntax, if the node does not specify a format. Defaults to whether the phpVersion support short array syntax.
  • param array{phpVersion?: \PhpVersion, newline?: string, indent?: string, shortArraySyntax?: bool} $options Dictionary of formatting options
public PhpParser\PrettyPrinterAbstract::prettyPrint(array $stmts) : string
 

Pretty prints an array of statements.

  • param \Node[] $stmts Array of statements
  • return string Pretty printed statements
public PhpParser\PrettyPrinterAbstract::prettyPrintExpr(PhpParser\Node\Expr $node) : string
 

Pretty prints an expression.

  • param \Expr $node Expression node
  • return string Pretty printed node
public PhpParser\PrettyPrinterAbstract::prettyPrintFile(array $stmts) : string
 

Pretty prints a file of statements (includes the opening tag if it is required).

  • param \Node[] $stmts Array of statements
  • return string Pretty printed statements
public PhpParser\PrettyPrinterAbstract::printFormatPreserving(array $stmts, array $origStmts, array $origTokens) : string
 

Perform a format-preserving pretty print of an AST.

The format preservation is best effort. For some changes to the AST the formatting will not be preserved (at least not locally).

In order to use this method a number of prerequisites must be satisfied:

  • The startTokenPos and endTokenPos attributes in the lexer must be enabled.
  • The CloningVisitor must be run on the AST prior to modification.
  • The original tokens must be provided, using the getTokens() method on the lexer.
  • param \Node[] $stmts Modified AST with links to original AST
  • param \Node[] $origStmts Original AST with token offset information
  • param \Token[] $origTokens Tokens of the original code
Constants
protected PhpParser\PrettyPrinterAbstract::FIXUP_BRACED_NAME = 6
protected PhpParser\PrettyPrinterAbstract::FIXUP_CALL_LHS = 3
protected PhpParser\PrettyPrinterAbstract::FIXUP_DEREF_LHS = 4
protected PhpParser\PrettyPrinterAbstract::FIXUP_ENCAPSED = 8
protected PhpParser\PrettyPrinterAbstract::FIXUP_NEW = 9
protected PhpParser\PrettyPrinterAbstract::FIXUP_PREC_LEFT = 0
protected PhpParser\PrettyPrinterAbstract::FIXUP_PREC_RIGHT = 1
protected PhpParser\PrettyPrinterAbstract::FIXUP_PREC_UNARY = 2
protected PhpParser\PrettyPrinterAbstract::FIXUP_STATIC_DEREF_LHS = 5
protected PhpParser\PrettyPrinterAbstract::FIXUP_VAR_BRACED_NAME = 7
protected PhpParser\PrettyPrinterAbstract::MAX_PRECEDENCE = 1000
Properties
protected bool PhpParser\PrettyPrinterAbstract::$canUseSemicolonNamespaces
 
  • var bool Whether semicolon namespaces can be used (i.e. no global namespace is used)
protected ?string PhpParser\PrettyPrinterAbstract::$docStringEndToken
 
  • var string|null Token placed at end of doc string to ensure it is followed by a newline. Null if flexible doc strings are used.
protected array PhpParser\PrettyPrinterAbstract::$emptyListInsertionMap
 
  • var array<string,array{: int|string|null, : string, : string}>
protected array PhpParser\PrettyPrinterAbstract::$fixupMap
 
  • var array<string,array<string,int>> Map from token classes and subnode names to FIXUP_* constants. This is used during format-preserving prints to place additional parens/braces if necessary.
protected int PhpParser\PrettyPrinterAbstract::$indentLevel
 
  • var int Current indentation level.
protected array PhpParser\PrettyPrinterAbstract::$insertionMap
 
  • var array<string,array{: int|string|null, : bool, : string|null, : string|null}> Map from "{$node->getType()}->{$subNode}" to [$find, $beforeToken, $extraLeft, $extraRight]. $find is an optional token after which the insertion occurs. $extraLeft/Right are optionally added before/after the main insertions.
protected array PhpParser\PrettyPrinterAbstract::$labelCharMap
 
  • var array<string,bool> Map determining whether a certain character is a label character
protected array PhpParser\PrettyPrinterAbstract::$listInsertionMap
 
  • var array<string,string> Map From "{$class}->{$subNode}" to string that should be inserted between elements of this list subnode.
protected array PhpParser\PrettyPrinterAbstract::$modifierChangeMap
 
  • var array<string,array{: string, : int}> Map from "{$class}->{$subNode}" to [$printFn, $token] where $printFn is the function to print the modifiers and $token is the token before which the modifiers should be reprinted.
protected string PhpParser\PrettyPrinterAbstract::$newline
 
  • var string Newline style. Does not include current indentation.
protected string PhpParser\PrettyPrinterAbstract::$nl
 
  • var string Newline including current indentation.
protected PhpParser\Internal\Differ PhpParser\PrettyPrinterAbstract::$nodeListDiffer
 
  • var \Internal\Differ<\Node> Differ for node lists
protected ?PhpParser\Internal\TokenStream PhpParser\PrettyPrinterAbstract::$origTokens
 
  • var \TokenStream|null Original tokens for use in format-preserving pretty print
protected PhpParser\PhpVersion PhpParser\PrettyPrinterAbstract::$phpVersion
 
  • var \PhpVersion PHP version to target
protected array PhpParser\PrettyPrinterAbstract::$precedenceMap = ['PhpParser\Node\Expr\Clone_' => [-10, 0, 1], 'PhpParser\Node\Expr\BinaryOp\Pow' => [0, 0, 1], 'PhpParser\Node\Expr\BitwiseNot' => [10, -1, -1], 'PhpParser\Node\Expr\UnaryPlus' => [10, -1, -1], 'PhpParser\Node\Expr\UnaryMinus' => [10, -1, -1], 'PhpParser\Node\Expr\Cast\Int_' => [10, -1, -1], 'PhpParser\Node\Expr\Cast\Double' => [10, -1, -1], 'PhpParser\Node\Expr\Cast\String_' => [10, -1, -1], 'PhpParser\Node\Expr\Cast\Array_' => [10, -1, -1], 'PhpParser\Node\Expr\Cast\Object_' => [10, -1, -1], 'PhpParser\Node\Expr\Cast\Bool_' => [10, -1, -1], 'PhpParser\Node\Expr\Cast\Unset_' => [10, -1, -1], 'PhpParser\Node\Expr\ErrorSuppress' => [10, -1, -1], 'PhpParser\Node\Expr\Instanceof_' => [20, -1, -1], 'PhpParser\Node\Expr\BooleanNot' => [30, -1, -1], 'PhpParser\Node\Expr\BinaryOp\Mul' => [40, 41, 40], 'PhpParser\Node\Expr\BinaryOp\Div' => [40, 41, 40], 'PhpParser\Node\Expr\BinaryOp\Mod' => [40, 41, 40], 'PhpParser\Node\Expr\BinaryOp\Plus' => [50, 51, 50], 'PhpParser\Node\Expr\BinaryOp\Minus' => [50, 51, 50], 'PhpParser\Node\Expr\BinaryOp\Concat' => [50, 51, 50], 'PhpParser\Node\Expr\BinaryOp\ShiftLeft' => [60, 61, 60], 'PhpParser\Node\Expr\BinaryOp\ShiftRight' => [60, 61, 60], 'PhpParser\Node\Expr\BinaryOp\Smaller' => [70, 70, 70], 'PhpParser\Node\Expr\BinaryOp\SmallerOrEqual' => [70, 70, 70], 'PhpParser\Node\Expr\BinaryOp\Greater' => [70, 70, 70], 'PhpParser\Node\Expr\BinaryOp\GreaterOrEqual' => [70, 70, 70], 'PhpParser\Node\Expr\BinaryOp\Equal' => [80, 80, 80], 'PhpParser\Node\Expr\BinaryOp\NotEqual' => [80, 80, 80], 'PhpParser\Node\Expr\BinaryOp\Identical' => [80, 80, 80], 'PhpParser\Node\Expr\BinaryOp\NotIdentical' => [80, 80, 80], 'PhpParser\Node\Expr\BinaryOp\Spaceship' => [80, 80, 80], 'PhpParser\Node\Expr\BinaryOp\BitwiseAnd' => [90, 91, 90], 'PhpParser\Node\Expr\BinaryOp\BitwiseXor' => [100, 101, 100], 'PhpParser\Node\Expr\BinaryOp\BitwiseOr' => [110, 111, 110], 'PhpParser\Node\Expr\BinaryOp\BooleanAnd' => [120, 121, 120], 'PhpParser\Node\Expr\BinaryOp\BooleanOr' => [130, 131, 130], 'PhpParser\Node\Expr\BinaryOp\Coalesce' => [140, 140, 141], 'PhpParser\Node\Expr\Ternary' => [150, 150, 150], 'PhpParser\Node\Expr\Assign' => [160, -1, -1], 'PhpParser\Node\Expr\AssignRef' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Plus' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Minus' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Mul' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Div' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Concat' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Mod' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\BitwiseAnd' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\BitwiseOr' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\BitwiseXor' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\ShiftLeft' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\ShiftRight' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Pow' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Coalesce' => [160, -1, -1], 'PhpParser\Node\Expr\YieldFrom' => [170, -1, -1], 'PhpParser\Node\Expr\Yield_' => [175, -1, -1], 'PhpParser\Node\Expr\Print_' => [180, -1, -1], 'PhpParser\Node\Expr\BinaryOp\LogicalAnd' => [190, 191, 190], 'PhpParser\Node\Expr\BinaryOp\LogicalXor' => [200, 201, 200], 'PhpParser\Node\Expr\BinaryOp\LogicalOr' => [210, 211, 210], 'PhpParser\Node\Expr\Include_' => [220, -1, -1], 'PhpParser\Node\Expr\ArrowFunction' => [230, -1, -1], 'PhpParser\Node\Expr\Throw_' => [240, -1, -1]]
 
  • var array<class-string,array{: int, : int, : int}>
protected array PhpParser\PrettyPrinterAbstract::$removalMap
 
  • var array<string,array{left?: int|string, right?: int|string}> Map from "{$node->getType()}->{$subNode}" to ['left' => $l, 'right' => $r], where $l and $r specify the token type that needs to be stripped when removing this node.
protected bool PhpParser\PrettyPrinterAbstract::$shortArraySyntax
 
  • var bool Whether to use short array syntax if the node specifies no preference
Methods
protected PhpParser\PrettyPrinterAbstract::callLhsRequiresParens(PhpParser\Node $node) : bool
 

Determines whether the LHS of a call must be wrapped in parenthesis.

  • param \Node $node LHS of a call
  • return bool Whether parentheses are required
protected containsEndLabel(string $string, string $label, bool $atStart = true) : bool
protected PhpParser\PrettyPrinterAbstract::dereferenceLhsRequiresParens(PhpParser\Node $node) : bool
 

Determines whether the LHS of an array/object operation must be wrapped in parentheses.

  • param \Node $node LHS of dereferencing operation
  • return bool Whether parentheses are required
protected encapsedContainsEndLabel(array $parts, string $label) : bool
 
  • param (\Expr|\Node\InterpolatedStringPart)[] $parts
protected escapeString(string $string, ?string $quote) : string
protected PhpParser\PrettyPrinterAbstract::handleMagicTokens(string $str) : string
 

Handles (and removes) doc-string-end tokens.

protected hasNodeWithComments(array $nodes) : bool
 
  • param \Node[] $nodes
protected PhpParser\PrettyPrinterAbstract::indent() : void
 

Increase indentation level.

protected PhpParser\PrettyPrinterAbstract::initializeEmptyListInsertionMap() : void
protected PhpParser\PrettyPrinterAbstract::initializeFixupMap() : void
 

Lazily initializes fixup map.

The fixup map is used to determine whether a certain subnode of a certain node may require some kind of "fixup" operation, e.g. the addition of parenthesis or braces.

protected PhpParser\PrettyPrinterAbstract::initializeInsertionMap() : void
protected PhpParser\PrettyPrinterAbstract::initializeLabelCharMap() : void
 

Lazily initializes label char map.

The label char map determines whether a certain character may occur in a label.

protected PhpParser\PrettyPrinterAbstract::initializeListInsertionMap() : void
protected PhpParser\PrettyPrinterAbstract::initializeModifierChangeMap() : void
protected PhpParser\PrettyPrinterAbstract::initializeNodeListDiffer() : void
 

Lazily initializes node list differ.

The node list differ is used to determine differences between two array subnodes.

protected PhpParser\PrettyPrinterAbstract::initializeRemovalMap() : void
 

Lazily initializes the removal map.

The removal map is used to determine which additional tokens should be removed when a certain node is replaced by null.

protected PhpParser\PrettyPrinterAbstract::isMultiline(array $nodes) : bool
 

Determine whether a list of nodes uses multiline formatting.

  • param (\Node|null)[] $nodes Node list
  • return bool Whether multiline formatting is used
protected PhpParser\PrettyPrinterAbstract::newOperandRequiresParens(PhpParser\Node $node) : bool
 

Determines whether an expression used in "new" or "instanceof" requires parentheses.

  • param \Node $node New or instanceof operand
  • return bool Whether parentheses are required
protected PhpParser\PrettyPrinterAbstract::outdent() : void
 

Decrease indentation level.

protected PhpParser\PrettyPrinterAbstract::p(PhpParser\Node $node, int $precedence = 1000self::MAX_PRECEDENCE, int $lhsPrecedence = 1000self::MAX_PRECEDENCE, bool $parentFormatPreserved = false) : string
 

Pretty prints a node.

This method also handles formatting preservation for nodes.

  • param \Node $node Node to be pretty printed
  • param int $precedence Precedence of parent operator
  • param int $lhsPrecedence Precedence for unary operator on LHS of binary operator
  • param bool $parentFormatPreserved Whether parent node has preserved formatting
  • return string Pretty printed node
protected pArg(PhpParser\Node\Arg $node) : string
protected PhpParser\PrettyPrinterAbstract::pArray(array $nodes, array $origNodes, int $pos, int $indentAdjustment, string $parentNodeClass, string $subNodeName, ?int $fixup) : ?string
 

Perform a format-preserving pretty print of an array.

  • param \Node[] $nodes New nodes
  • param \Node[] $origNodes Original nodes
  • param int $pos Current token position (updated by reference)
  • param int $indentAdjustment Adjustment for indentation
  • param string $parentNodeClass Class of the containing node.
  • param string $subNodeName Name of array subnode.
  • param null|int $fixup Fixup information for array item nodes
  • return null|string Result of pretty print or null if cannot preserve formatting
protected pArrayItem(PhpParser\Node\ArrayItem $node) : string
protected pAttrGroups(array $nodes, bool $inline = false) : string
 
  • param \Node\AttributeGroup[] $nodes
protected pAttribute(PhpParser\Node\Attribute $node) : string
protected pAttributeGroup(PhpParser\Node\AttributeGroup $node) : string
protected pCallLhs(PhpParser\Node $node) : string
protected pClassCommon(PhpParser\Node\Stmt\Class_ $node, string $afterClassToken) : string
protected pClosureUse(PhpParser\Node\ClosureUse $node) : string
protected PhpParser\PrettyPrinterAbstract::pCommaSeparated(array $nodes) : string
 

Pretty prints an array of nodes and implodes the printed values with commas.

  • param \Node[] $nodes Array of Nodes to be printed
  • return string Comma separated pretty printed nodes
protected PhpParser\PrettyPrinterAbstract::pCommaSeparatedMultiline(array $nodes, bool $trailingComma) : string
 

Pretty prints a comma-separated list of nodes in multiline style, including comments.

The result includes a leading newline and one level of indentation (same as pStmts).

  • param \Node[] $nodes Array of Nodes to be printed
  • param bool $trailingComma Whether to use a trailing comma
  • return string Comma separated pretty printed nodes in multiline style
protected PhpParser\PrettyPrinterAbstract::pComments(array $comments) : string
 

Prints reformatted text of the passed comments.

  • param \Comment[] $comments List of comments
  • return string Reformatted text of comments
protected pConst(PhpParser\Node\Const_ $node) : string
protected pDeclareItem(PhpParser\Node\DeclareItem $node) : string
protected pDereferenceLhs(PhpParser\Node $node) : string
protected pEncapsList(array $encapsList, ?string $quote) : string
 
  • param (\Expr|\Node\InterpolatedStringPart)[] $encapsList
protected pExpr_Array(PhpParser\Node\Expr\Array_ $node) : string
protected pExpr_ArrayDimFetch(PhpParser\Node\Expr\ArrayDimFetch $node) : string
protected pExpr_ArrowFunction(PhpParser\Node\Expr\ArrowFunction $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_Assign(PhpParser\Node\Expr\Assign $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_AssignOp_BitwiseAnd(PhpParser\Node\Expr\AssignOp\BitwiseAnd $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_AssignOp_BitwiseOr(PhpParser\Node\Expr\AssignOp\BitwiseOr $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_AssignOp_BitwiseXor(PhpParser\Node\Expr\AssignOp\BitwiseXor $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_AssignOp_Coalesce(PhpParser\Node\Expr\AssignOp\Coalesce $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_AssignOp_Concat(PhpParser\Node\Expr\AssignOp\Concat $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_AssignOp_Div(PhpParser\Node\Expr\AssignOp\Div $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_AssignOp_Minus(PhpParser\Node\Expr\AssignOp\Minus $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_AssignOp_Mod(PhpParser\Node\Expr\AssignOp\Mod $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_AssignOp_Mul(PhpParser\Node\Expr\AssignOp\Mul $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_AssignOp_Plus(PhpParser\Node\Expr\AssignOp\Plus $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_AssignOp_Pow(PhpParser\Node\Expr\AssignOp\Pow $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_AssignOp_ShiftLeft(PhpParser\Node\Expr\AssignOp\ShiftLeft $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_AssignOp_ShiftRight(PhpParser\Node\Expr\AssignOp\ShiftRight $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_AssignRef(PhpParser\Node\Expr\AssignRef $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_BitwiseAnd(PhpParser\Node\Expr\BinaryOp\BitwiseAnd $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_BitwiseOr(PhpParser\Node\Expr\BinaryOp\BitwiseOr $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_BitwiseXor(PhpParser\Node\Expr\BinaryOp\BitwiseXor $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_BooleanAnd(PhpParser\Node\Expr\BinaryOp\BooleanAnd $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_BooleanOr(PhpParser\Node\Expr\BinaryOp\BooleanOr $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_Coalesce(PhpParser\Node\Expr\BinaryOp\Coalesce $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_Concat(PhpParser\Node\Expr\BinaryOp\Concat $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_Div(PhpParser\Node\Expr\BinaryOp\Div $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_Equal(PhpParser\Node\Expr\BinaryOp\Equal $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_Greater(PhpParser\Node\Expr\BinaryOp\Greater $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_GreaterOrEqual(PhpParser\Node\Expr\BinaryOp\GreaterOrEqual $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_Identical(PhpParser\Node\Expr\BinaryOp\Identical $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_LogicalAnd(PhpParser\Node\Expr\BinaryOp\LogicalAnd $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_LogicalOr(PhpParser\Node\Expr\BinaryOp\LogicalOr $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_LogicalXor(PhpParser\Node\Expr\BinaryOp\LogicalXor $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_Minus(PhpParser\Node\Expr\BinaryOp\Minus $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_Mod(PhpParser\Node\Expr\BinaryOp\Mod $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_Mul(PhpParser\Node\Expr\BinaryOp\Mul $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_NotEqual(PhpParser\Node\Expr\BinaryOp\NotEqual $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_NotIdentical(PhpParser\Node\Expr\BinaryOp\NotIdentical $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_Plus(PhpParser\Node\Expr\BinaryOp\Plus $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_Pow(PhpParser\Node\Expr\BinaryOp\Pow $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_ShiftLeft(PhpParser\Node\Expr\BinaryOp\ShiftLeft $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_ShiftRight(PhpParser\Node\Expr\BinaryOp\ShiftRight $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_Smaller(PhpParser\Node\Expr\BinaryOp\Smaller $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_SmallerOrEqual(PhpParser\Node\Expr\BinaryOp\SmallerOrEqual $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BinaryOp_Spaceship(PhpParser\Node\Expr\BinaryOp\Spaceship $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BitwiseNot(PhpParser\Node\Expr\BitwiseNot $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_BooleanNot(PhpParser\Node\Expr\BooleanNot $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_Cast_Array(PhpParser\Node\Expr\Cast\Array_ $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_Cast_Bool(PhpParser\Node\Expr\Cast\Bool_ $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_Cast_Double(PhpParser\Node\Expr\Cast\Double $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_Cast_Int(PhpParser\Node\Expr\Cast\Int_ $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_Cast_Object(PhpParser\Node\Expr\Cast\Object_ $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_Cast_String(PhpParser\Node\Expr\Cast\String_ $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_Cast_Unset(PhpParser\Node\Expr\Cast\Unset_ $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_ClassConstFetch(PhpParser\Node\Expr\ClassConstFetch $node) : string
protected pExpr_Clone(PhpParser\Node\Expr\Clone_ $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_Closure(PhpParser\Node\Expr\Closure $node) : string
protected pExpr_ConstFetch(PhpParser\Node\Expr\ConstFetch $node) : string
protected pExpr_Empty(PhpParser\Node\Expr\Empty_ $node) : string
protected pExpr_Error(PhpParser\Node\Expr\Error $node) : string
protected pExpr_ErrorSuppress(PhpParser\Node\Expr\ErrorSuppress $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_Eval(PhpParser\Node\Expr\Eval_ $node) : string
protected pExpr_Exit(PhpParser\Node\Expr\Exit_ $node) : string
protected pExpr_FuncCall(PhpParser\Node\Expr\FuncCall $node) : string
protected pExpr_Include(PhpParser\Node\Expr\Include_ $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_Instanceof(PhpParser\Node\Expr\Instanceof_ $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_Isset(PhpParser\Node\Expr\Isset_ $node) : string
protected pExpr_List(PhpParser\Node\Expr\List_ $node) : string
protected pExpr_Match(PhpParser\Node\Expr\Match_ $node) : string
protected pExpr_MethodCall(PhpParser\Node\Expr\MethodCall $node) : string
protected pExpr_New(PhpParser\Node\Expr\New_ $node) : string
protected pExpr_NullsafeMethodCall(PhpParser\Node\Expr\NullsafeMethodCall $node) : string
protected pExpr_NullsafePropertyFetch(PhpParser\Node\Expr\NullsafePropertyFetch $node) : string
protected pExpr_PostDec(PhpParser\Node\Expr\PostDec $node) : string
protected pExpr_PostInc(PhpParser\Node\Expr\PostInc $node) : string
protected pExpr_PreDec(PhpParser\Node\Expr\PreDec $node) : string
protected pExpr_PreInc(PhpParser\Node\Expr\PreInc $node) : string
protected pExpr_Print(PhpParser\Node\Expr\Print_ $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_PropertyFetch(PhpParser\Node\Expr\PropertyFetch $node) : string
protected pExpr_ShellExec(PhpParser\Node\Expr\ShellExec $node) : string
protected pExpr_StaticCall(PhpParser\Node\Expr\StaticCall $node) : string
protected pExpr_StaticPropertyFetch(PhpParser\Node\Expr\StaticPropertyFetch $node) : string
protected pExpr_Ternary(PhpParser\Node\Expr\Ternary $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_Throw(PhpParser\Node\Expr\Throw_ $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_UnaryMinus(PhpParser\Node\Expr\UnaryMinus $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_UnaryPlus(PhpParser\Node\Expr\UnaryPlus $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_Variable(PhpParser\Node\Expr\Variable $node) : string
protected pExpr_Yield(PhpParser\Node\Expr\Yield_ $node, int $precedence, int $lhsPrecedence) : string
protected pExpr_YieldFrom(PhpParser\Node\Expr\YieldFrom $node, int $precedence, int $lhsPrecedence) : string
protected PhpParser\PrettyPrinterAbstract::pFallback(PhpParser\Node $node, int $precedence, int $lhsPrecedence) : string
protected PhpParser\PrettyPrinterAbstract::pFixup(int $fixup, PhpParser\Node $subNode, ?string $parentClass, int $subStartPos, int $subEndPos) : string
 

Print node with fixups.

Fixups here refer to the addition of extra parentheses, braces or other characters, that are required to preserve program semantics in a certain context (e.g. to maintain precedence or because only certain expressions are allowed in certain places).

  • param int $fixup Fixup type
  • param \Node $subNode Subnode to print
  • param string|null $parentClass Class of parent node
  • param int $subStartPos Original start pos of subnode
  • param int $subEndPos Original end pos of subnode
  • return string Result of fixed-up print of subnode
protected pIdentifier(PhpParser\Node\Identifier $node) : string
protected PhpParser\PrettyPrinterAbstract::pImplode(array $nodes, string $glue = '') : string
 

Pretty prints an array of nodes and implodes the printed values.

  • param \Node[] $nodes Array of Nodes to be printed
  • param string $glue Character to implode with
  • return string Imploded pretty printed nodes> $pre
protected PhpParser\PrettyPrinterAbstract::pInfixOp(string $class, PhpParser\Node $leftNode, string $operatorString, PhpParser\Node $rightNode, int $precedence, int $lhsPrecedence) : string
 

Pretty-print an infix operation while taking precedence into account.

  • param string $class Node class of operator
  • param \Node $leftNode Left-hand side node
  • param string $operatorString String representation of the operator
  • param \Node $rightNode Right-hand side node
  • param int $precedence Precedence of parent operator
  • param int $lhsPrecedence Precedence for unary operator on LHS of binary operator
  • return string Pretty printed infix operation
protected pIntersectionType(PhpParser\Node\IntersectionType $node) : string
protected pKey(?PhpParser\Node $node) : string
protected pMatchArm(PhpParser\Node\MatchArm $node) : string
protected pMaybeMultiline(array $nodes, bool $trailingComma = false) : string
 
  • param \Node[] $nodes
protected PhpParser\PrettyPrinterAbstract::pModifiers(int $modifiers) : string
 

Print modifiers, including trailing whitespace.

  • param int $modifiers Modifier mask to print
  • return string Printed modifiers
protected pName(PhpParser\Node\Name $node) : string
protected pName_FullyQualified(PhpParser\Node\Name\FullyQualified $node) : string
protected pName_Relative(PhpParser\Node\Name\Relative $node) : string
protected pNewOperand(PhpParser\Node $node) : string
protected pNullableType(PhpParser\Node\NullableType $node) : string
protected pObjectProperty(PhpParser\Node $node) : string
protected pParam(PhpParser\Node\Param $node) : string
protected PhpParser\PrettyPrinterAbstract::pPostfixOp(string $class, PhpParser\Node $node, string $operatorString, int $precedence, int $lhsPrecedence) : string
 

Pretty-print a postfix operation while taking precedence into account.

  • param string $class Node class of operator
  • param string $operatorString String representation of the operator
  • param \Node $node Node
  • param int $precedence Precedence of parent operator
  • param int $lhsPrecedence Precedence for unary operator on LHS of binary operator
  • return string Pretty printed postfix operation
protected PhpParser\PrettyPrinterAbstract::pPrefixOp(string $class, string $operatorString, PhpParser\Node $node, int $precedence, int $lhsPrecedence) : string
 

Pretty-print a prefix operation while taking precedence into account.

  • param string $class Node class of operator
  • param string $operatorString String representation of the operator
  • param \Node $node Node
  • param int $precedence Precedence of parent operator
  • param int $lhsPrecedence Precedence for unary operator on LHS of binary operator
  • return string Pretty printed prefix operation
protected pPropertyHook(PhpParser\Node\PropertyHook $node) : string
protected pPropertyItem(PhpParser\Node\PropertyItem $node) : string
protected PhpParser\PrettyPrinterAbstract::preprocessNodes(array $nodes) : void
 

Preprocesses the top-level nodes to initialize pretty printer state.

  • param \Node[] $nodes Array of nodes
protected pScalar_Float(PhpParser\Node\Scalar\Float_ $node) : string
protected pScalar_Int(PhpParser\Node\Scalar\Int_ $node) : string
protected pScalar_InterpolatedString(PhpParser\Node\Scalar\InterpolatedString $node) : string
protected pScalar_MagicConst_Class(PhpParser\Node\Scalar\MagicConst\Class_ $node) : string
protected pScalar_MagicConst_Dir(PhpParser\Node\Scalar\MagicConst\Dir $node) : string
protected pScalar_MagicConst_File(PhpParser\Node\Scalar\MagicConst\File $node) : string
protected pScalar_MagicConst_Function(PhpParser\Node\Scalar\MagicConst\Function_ $node) : string
protected pScalar_MagicConst_Line(PhpParser\Node\Scalar\MagicConst\Line $node) : string
protected pScalar_MagicConst_Method(PhpParser\Node\Scalar\MagicConst\Method $node) : string
protected pScalar_MagicConst_Namespace(PhpParser\Node\Scalar\MagicConst\Namespace_ $node) : string
protected pScalar_MagicConst_Property(PhpParser\Node\Scalar\MagicConst\Property $node) : string
protected pScalar_MagicConst_Trait(PhpParser\Node\Scalar\MagicConst\Trait_ $node) : string
protected pScalar_String(PhpParser\Node\Scalar\String_ $node) : string
protected pSingleQuotedString(string $string) : string
protected PhpParser\PrettyPrinterAbstract::pStatic(bool $static) : string
protected pStaticDereferenceLhs(PhpParser\Node $node) : string
protected pStaticVar(PhpParser\Node\StaticVar $node) : string
protected pStmt_Block(PhpParser\Node\Stmt\Block $node) : string
protected pStmt_Break(PhpParser\Node\Stmt\Break_ $node) : string
protected pStmt_Case(PhpParser\Node\Stmt\Case_ $node) : string
protected pStmt_Catch(PhpParser\Node\Stmt\Catch_ $node) : string
protected pStmt_Class(PhpParser\Node\Stmt\Class_ $node) : string
protected pStmt_ClassConst(PhpParser\Node\Stmt\ClassConst $node) : string
protected pStmt_ClassMethod(PhpParser\Node\Stmt\ClassMethod $node) : string
protected pStmt_Const(PhpParser\Node\Stmt\Const_ $node) : string
protected pStmt_Continue(PhpParser\Node\Stmt\Continue_ $node) : string
protected pStmt_Declare(PhpParser\Node\Stmt\Declare_ $node) : string
protected pStmt_Do(PhpParser\Node\Stmt\Do_ $node) : string
protected pStmt_Echo(PhpParser\Node\Stmt\Echo_ $node) : string
protected pStmt_Else(PhpParser\Node\Stmt\Else_ $node) : string
protected pStmt_ElseIf(PhpParser\Node\Stmt\ElseIf_ $node) : string
protected pStmt_Enum(PhpParser\Node\Stmt\Enum_ $node) : string
protected pStmt_EnumCase(PhpParser\Node\Stmt\EnumCase $node) : string
protected pStmt_Expression(PhpParser\Node\Stmt\Expression $node) : string
protected pStmt_Finally(PhpParser\Node\Stmt\Finally_ $node) : string
protected pStmt_For(PhpParser\Node\Stmt\For_ $node) : string
protected pStmt_Foreach(PhpParser\Node\Stmt\Foreach_ $node) : string
protected pStmt_Function(PhpParser\Node\Stmt\Function_ $node) : string
protected pStmt_Global(PhpParser\Node\Stmt\Global_ $node) : string
protected pStmt_Goto(PhpParser\Node\Stmt\Goto_ $node) : string
protected pStmt_GroupUse(PhpParser\Node\Stmt\GroupUse $node) : string
protected pStmt_HaltCompiler(PhpParser\Node\Stmt\HaltCompiler $node) : string
protected pStmt_If(PhpParser\Node\Stmt\If_ $node) : string
protected pStmt_InlineHTML(PhpParser\Node\Stmt\InlineHTML $node) : string
protected pStmt_Interface(PhpParser\Node\Stmt\Interface_ $node) : string
protected pStmt_Label(PhpParser\Node\Stmt\Label $node) : string
protected pStmt_Namespace(PhpParser\Node\Stmt\Namespace_ $node) : string
protected pStmt_Nop(PhpParser\Node\Stmt\Nop $node) : string
protected pStmt_Property(PhpParser\Node\Stmt\Property $node) : string
protected pStmt_Return(PhpParser\Node\Stmt\Return_ $node) : string
protected pStmt_Static(PhpParser\Node\Stmt\Static_ $node) : string
protected pStmt_Switch(PhpParser\Node\Stmt\Switch_ $node) : string
protected pStmt_Trait(PhpParser\Node\Stmt\Trait_ $node) : string
protected pStmt_TraitUse(PhpParser\Node\Stmt\TraitUse $node) : string
protected pStmt_TraitUseAdaptation_Alias(PhpParser\Node\Stmt\TraitUseAdaptation\Alias $node) : string
protected pStmt_TraitUseAdaptation_Precedence(PhpParser\Node\Stmt\TraitUseAdaptation\Precedence $node) : string
protected pStmt_TryCatch(PhpParser\Node\Stmt\TryCatch $node) : string
protected pStmt_Unset(PhpParser\Node\Stmt\Unset_ $node) : string
protected pStmt_Use(PhpParser\Node\Stmt\Use_ $node) : string
protected pStmt_While(PhpParser\Node\Stmt\While_ $node) : string
protected PhpParser\PrettyPrinterAbstract::pStmts(array $nodes, bool $indent = true) : string
 

Pretty prints an array of nodes (statements) and indents them optionally.

  • param \Node[] $nodes Array of nodes
  • param bool $indent Whether to indent the printed nodes
  • return string Pretty printed statements
protected pUnionType(PhpParser\Node\UnionType $node) : string
protected pUseItem(PhpParser\Node\UseItem $node) : string
protected pUseType(int $type) : string
protected pVariadicPlaceholder(PhpParser\Node\VariadicPlaceholder $node) : string
protected pVarLikeIdentifier(PhpParser\Node\VarLikeIdentifier $node) : string
protected PhpParser\PrettyPrinterAbstract::resetState() : void
 

Reset pretty printing state.

protected PhpParser\PrettyPrinterAbstract::safeAppend(string $str, string $append) : void
 

Appends to a string, ensuring whitespace between label characters.

Example: "echo" and "$x" result in "echo$x", but "echo" and "x" result in "echo x". Without safeAppend the result would be "echox", which does not preserve semantics.

protected PhpParser\PrettyPrinterAbstract::setIndentLevel(int $level) : void
 

Set indentation level

  • param int $level Level in number of spaces
protected PhpParser\PrettyPrinterAbstract::staticDereferenceLhsRequiresParens(PhpParser\Node $node) : bool
 

Determines whether the LHS of a static operation must be wrapped in parentheses.

  • param \Node $node LHS of dereferencing operation
  • return bool Whether parentheses are required
Methods
private indentString(string $str) : string
© 2025 Bruce Wells
Search Namespaces \ Classes
Configuration