Documentation

Standard extends PrettyPrinterAbstract
in package

Table of Contents

FIXUP_BRACED_NAME  = 4
FIXUP_CALL_LHS  = 2
FIXUP_DEREF_LHS  = 3
FIXUP_ENCAPSED  = 6
FIXUP_PREC_LEFT  = 0
FIXUP_PREC_RIGHT  = 1
FIXUP_VAR_BRACED_NAME  = 5
$canUseSemicolonNamespaces  : bool
$docStringEndToken  : string
$emptyListInsertionMap  : mixed
$fixupMap  : array<string|int, array<string|int, int>>
$indentLevel  : int
$insertionMap  : array<string|int, mixed>
$labelCharMap  : array<string|int, bool>
$listInsertionMap  : array<string|int, string>
$modifierChangeMap  : array<string|int, int>
$nl  : string
$nodeListDiffer  : Differ
$options  : array<string|int, mixed>
$origTokens  : TokenStream
$precedenceMap  : mixed
$removalMap  : array<string|int, array<string|int, int>>
__construct()  : mixed
Creates a pretty printer instance using the given options.
prettyPrint()  : string
Pretty prints an array of statements.
prettyPrintExpr()  : string
Pretty prints an expression.
prettyPrintFile()  : string
Pretty prints a file of statements (includes the opening <?php tag if it is required).
printFormatPreserving()  : string
Perform a format-preserving pretty print of an AST.
callLhsRequiresParens()  : bool
Determines whether the LHS of a call must be wrapped in parenthesis.
containsEndLabel()  : mixed
dereferenceLhsRequiresParens()  : bool
Determines whether the LHS of a dereferencing operation must be wrapped in parenthesis.
encapsedContainsEndLabel()  : mixed
escapeString()  : mixed
handleMagicTokens()  : string
Handles (and removes) no-indent and doc-string-end tokens.
hasNodeWithComments()  : bool
indent()  : mixed
Increase indentation level.
initializeEmptyListInsertionMap()  : mixed
initializeFixupMap()  : mixed
Lazily initializes fixup map.
initializeInsertionMap()  : mixed
initializeLabelCharMap()  : mixed
Lazily initializes label char map.
initializeListInsertionMap()  : mixed
initializeModifierChangeMap()  : mixed
initializeNodeListDiffer()  : mixed
Lazily initializes node list differ.
initializeRemovalMap()  : mixed
Lazily initializes the removal map.
isMultiline()  : bool
Determine whether a list of nodes uses multiline formatting.
outdent()  : mixed
Decrease indentation level.
p()  : string
Pretty prints a node.
pArg()  : mixed
pArray()  : null|string
Perform a format-preserving pretty print of an array.
pAttrGroups()  : string
pAttribute()  : mixed
pAttributeGroup()  : mixed
pCallLhs()  : mixed
pClassCommon()  : mixed
pCommaSeparated()  : string
Pretty prints an array of nodes and implodes the printed values with commas.
pCommaSeparatedMultiline()  : string
Pretty prints a comma-separated list of nodes in multiline style, including comments.
pComments()  : string
Prints reformatted text of the passed comments.
pConst()  : mixed
pDereferenceLhs()  : mixed
pEncapsList()  : mixed
pExpr_Array()  : mixed
pExpr_ArrayDimFetch()  : mixed
pExpr_ArrayItem()  : mixed
pExpr_ArrowFunction()  : mixed
pExpr_Assign()  : mixed
pExpr_AssignOp_BitwiseAnd()  : mixed
pExpr_AssignOp_BitwiseOr()  : mixed
pExpr_AssignOp_BitwiseXor()  : mixed
pExpr_AssignOp_Coalesce()  : mixed
pExpr_AssignOp_Concat()  : mixed
pExpr_AssignOp_Div()  : mixed
pExpr_AssignOp_Minus()  : mixed
pExpr_AssignOp_Mod()  : mixed
pExpr_AssignOp_Mul()  : mixed
pExpr_AssignOp_Plus()  : mixed
pExpr_AssignOp_Pow()  : mixed
pExpr_AssignOp_ShiftLeft()  : mixed
pExpr_AssignOp_ShiftRight()  : mixed
pExpr_AssignRef()  : mixed
pExpr_BinaryOp_BitwiseAnd()  : mixed
pExpr_BinaryOp_BitwiseOr()  : mixed
pExpr_BinaryOp_BitwiseXor()  : mixed
pExpr_BinaryOp_BooleanAnd()  : mixed
pExpr_BinaryOp_BooleanOr()  : mixed
pExpr_BinaryOp_Coalesce()  : mixed
pExpr_BinaryOp_Concat()  : mixed
pExpr_BinaryOp_Div()  : mixed
pExpr_BinaryOp_Equal()  : mixed
pExpr_BinaryOp_Greater()  : mixed
pExpr_BinaryOp_GreaterOrEqual()  : mixed
pExpr_BinaryOp_Identical()  : mixed
pExpr_BinaryOp_LogicalAnd()  : mixed
pExpr_BinaryOp_LogicalOr()  : mixed
pExpr_BinaryOp_LogicalXor()  : mixed
pExpr_BinaryOp_Minus()  : mixed
pExpr_BinaryOp_Mod()  : mixed
pExpr_BinaryOp_Mul()  : mixed
pExpr_BinaryOp_NotEqual()  : mixed
pExpr_BinaryOp_NotIdentical()  : mixed
pExpr_BinaryOp_Plus()  : mixed
pExpr_BinaryOp_Pow()  : mixed
pExpr_BinaryOp_ShiftLeft()  : mixed
pExpr_BinaryOp_ShiftRight()  : mixed
pExpr_BinaryOp_Smaller()  : mixed
pExpr_BinaryOp_SmallerOrEqual()  : mixed
pExpr_BinaryOp_Spaceship()  : mixed
pExpr_BitwiseNot()  : mixed
pExpr_BooleanNot()  : mixed
pExpr_Cast_Array()  : mixed
pExpr_Cast_Bool()  : mixed
pExpr_Cast_Double()  : mixed
pExpr_Cast_Int()  : mixed
pExpr_Cast_Object()  : mixed
pExpr_Cast_String()  : mixed
pExpr_Cast_Unset()  : mixed
pExpr_ClassConstFetch()  : mixed
pExpr_Clone()  : mixed
pExpr_Closure()  : mixed
pExpr_ClosureUse()  : mixed
pExpr_ConstFetch()  : mixed
pExpr_Empty()  : mixed
pExpr_Error()  : mixed
pExpr_ErrorSuppress()  : mixed
pExpr_Eval()  : mixed
pExpr_Exit()  : mixed
pExpr_FuncCall()  : mixed
pExpr_Include()  : mixed
pExpr_Instanceof()  : mixed
pExpr_Isset()  : mixed
pExpr_List()  : mixed
pExpr_Match()  : mixed
pExpr_MethodCall()  : mixed
pExpr_New()  : mixed
pExpr_NullsafeMethodCall()  : mixed
pExpr_NullsafePropertyFetch()  : mixed
pExpr_PostDec()  : mixed
pExpr_PostInc()  : mixed
pExpr_PreDec()  : mixed
pExpr_PreInc()  : mixed
pExpr_Print()  : mixed
pExpr_PropertyFetch()  : mixed
pExpr_ShellExec()  : mixed
pExpr_StaticCall()  : mixed
pExpr_StaticPropertyFetch()  : mixed
pExpr_Ternary()  : mixed
pExpr_Throw()  : mixed
pExpr_UnaryMinus()  : mixed
pExpr_UnaryPlus()  : mixed
pExpr_Variable()  : mixed
pExpr_Yield()  : mixed
pExpr_YieldFrom()  : mixed
pFallback()  : mixed
pFixup()  : string
Print node with fixups.
pIdentifier()  : mixed
pImplode()  : string
Pretty prints an array of nodes and implodes the printed values.
pInfixOp()  : string
Pretty-print an infix operation while taking precedence into account.
pIntersectionType()  : mixed
pMatchArm()  : mixed
pMaybeMultiline()  : mixed
pModifiers()  : string
Print modifiers, including trailing whitespace.
pName()  : mixed
pName_FullyQualified()  : mixed
pName_Relative()  : mixed
pNewVariable()  : mixed
pNullableType()  : mixed
pObjectProperty()  : mixed
pParam()  : mixed
pPostfixOp()  : string
Pretty-print a postfix operation while taking precedence into account.
pPrec()  : string
Prints an expression node with the least amount of parentheses necessary to preserve the meaning.
pPrefixOp()  : string
Pretty-print a prefix operation while taking precedence into account.
preprocessNodes()  : mixed
Preprocesses the top-level nodes to initialize pretty printer state.
pScalar_DNumber()  : mixed
pScalar_Encapsed()  : mixed
pScalar_EncapsedStringPart()  : mixed
pScalar_LNumber()  : mixed
pScalar_MagicConst_Class()  : mixed
pScalar_MagicConst_Dir()  : mixed
pScalar_MagicConst_File()  : mixed
pScalar_MagicConst_Function()  : mixed
pScalar_MagicConst_Line()  : mixed
pScalar_MagicConst_Method()  : mixed
pScalar_MagicConst_Namespace()  : mixed
pScalar_MagicConst_Trait()  : mixed
pScalar_String()  : mixed
pSingleQuotedString()  : mixed
pStmt_Break()  : mixed
pStmt_Case()  : mixed
pStmt_Catch()  : mixed
pStmt_Class()  : mixed
pStmt_ClassConst()  : mixed
pStmt_ClassMethod()  : mixed
pStmt_Const()  : mixed
pStmt_Continue()  : mixed
pStmt_Declare()  : mixed
pStmt_DeclareDeclare()  : mixed
pStmt_Do()  : mixed
pStmt_Echo()  : mixed
pStmt_Else()  : mixed
pStmt_ElseIf()  : mixed
pStmt_Enum()  : mixed
pStmt_EnumCase()  : mixed
pStmt_Expression()  : mixed
pStmt_Finally()  : mixed
pStmt_For()  : mixed
pStmt_Foreach()  : mixed
pStmt_Function()  : mixed
pStmt_Global()  : mixed
pStmt_Goto()  : mixed
pStmt_GroupUse()  : mixed
pStmt_HaltCompiler()  : mixed
pStmt_If()  : mixed
pStmt_InlineHTML()  : mixed
pStmt_Interface()  : mixed
pStmt_Label()  : mixed
pStmt_Namespace()  : mixed
pStmt_Nop()  : mixed
pStmt_Property()  : mixed
pStmt_PropertyProperty()  : mixed
pStmt_Return()  : mixed
pStmt_Static()  : mixed
pStmt_StaticVar()  : mixed
pStmt_Switch()  : mixed
pStmt_Throw()  : mixed
pStmt_Trait()  : mixed
pStmt_TraitUse()  : mixed
pStmt_TraitUseAdaptation_Alias()  : mixed
pStmt_TraitUseAdaptation_Precedence()  : mixed
pStmt_TryCatch()  : mixed
pStmt_Unset()  : mixed
pStmt_Use()  : mixed
pStmt_UseUse()  : mixed
pStmt_While()  : mixed
pStmts()  : string
Pretty prints an array of nodes (statements) and indents them optionally.
pUnionType()  : mixed
pUseType()  : mixed
pVariadicPlaceholder()  : mixed
pVarLikeIdentifier()  : mixed
resetState()  : mixed
Reset pretty printing state.
safeAppend()  : mixed
Appends to a string, ensuring whitespace between label characters.
setIndentLevel()  : mixed
Set indentation level

Constants

Properties

$canUseSemicolonNamespaces

protected bool $canUseSemicolonNamespaces

Whether semicolon namespaces can be used (i.e. no global namespace is used)

$docStringEndToken

protected string $docStringEndToken

Token placed at end of doc string to ensure it is followed by a newline.

$fixupMap

protected array<string|int, array<string|int, int>> $fixupMap

Map from token classes and subnode names to FIXUP_* constants. This is used during format-preserving prints to place additional parens/braces if necessary.

$insertionMap

protected array<string|int, mixed> $insertionMap

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.

$labelCharMap

protected array<string|int, bool> $labelCharMap

Map determining whether a certain character is a label character

$listInsertionMap

protected array<string|int, string> $listInsertionMap

Map From "{$node->getType()}->{$subNode}" to string that should be inserted between elements of this list subnode.

$modifierChangeMap

protected array<string|int, int> $modifierChangeMap

Map from "{$node->getType()}->{$subNode}" to token before which the modifiers should be reprinted.

$origTokens

protected TokenStream $origTokens

Original tokens for use in format-preserving pretty print

$precedenceMap

protected mixed $precedenceMap = [ // [precedence, associativity] // where for precedence -1 is %left, 0 is %nonassoc and 1 is %right \PhpParser\Node\Expr\BinaryOp\Pow::class => [0, 1], \PhpParser\Node\Expr\BitwiseNot::class => [10, 1], \PhpParser\Node\Expr\PreInc::class => [10, 1], \PhpParser\Node\Expr\PreDec::class => [10, 1], \PhpParser\Node\Expr\PostInc::class => [10, -1], \PhpParser\Node\Expr\PostDec::class => [10, -1], \PhpParser\Node\Expr\UnaryPlus::class => [10, 1], \PhpParser\Node\Expr\UnaryMinus::class => [10, 1], \PhpParser\Node\Expr\Cast\Int_::class => [10, 1], \PhpParser\Node\Expr\Cast\Double::class => [10, 1], \PhpParser\Node\Expr\Cast\String_::class => [10, 1], \PhpParser\Node\Expr\Cast\Array_::class => [10, 1], \PhpParser\Node\Expr\Cast\Object_::class => [10, 1], \PhpParser\Node\Expr\Cast\Bool_::class => [10, 1], \PhpParser\Node\Expr\Cast\Unset_::class => [10, 1], \PhpParser\Node\Expr\ErrorSuppress::class => [10, 1], \PhpParser\Node\Expr\Instanceof_::class => [20, 0], \PhpParser\Node\Expr\BooleanNot::class => [30, 1], \PhpParser\Node\Expr\BinaryOp\Mul::class => [40, -1], \PhpParser\Node\Expr\BinaryOp\Div::class => [40, -1], \PhpParser\Node\Expr\BinaryOp\Mod::class => [40, -1], \PhpParser\Node\Expr\BinaryOp\Plus::class => [50, -1], \PhpParser\Node\Expr\BinaryOp\Minus::class => [50, -1], \PhpParser\Node\Expr\BinaryOp\Concat::class => [50, -1], \PhpParser\Node\Expr\BinaryOp\ShiftLeft::class => [60, -1], \PhpParser\Node\Expr\BinaryOp\ShiftRight::class => [60, -1], \PhpParser\Node\Expr\BinaryOp\Smaller::class => [70, 0], \PhpParser\Node\Expr\BinaryOp\SmallerOrEqual::class => [70, 0], \PhpParser\Node\Expr\BinaryOp\Greater::class => [70, 0], \PhpParser\Node\Expr\BinaryOp\GreaterOrEqual::class => [70, 0], \PhpParser\Node\Expr\BinaryOp\Equal::class => [80, 0], \PhpParser\Node\Expr\BinaryOp\NotEqual::class => [80, 0], \PhpParser\Node\Expr\BinaryOp\Identical::class => [80, 0], \PhpParser\Node\Expr\BinaryOp\NotIdentical::class => [80, 0], \PhpParser\Node\Expr\BinaryOp\Spaceship::class => [80, 0], \PhpParser\Node\Expr\BinaryOp\BitwiseAnd::class => [90, -1], \PhpParser\Node\Expr\BinaryOp\BitwiseXor::class => [100, -1], \PhpParser\Node\Expr\BinaryOp\BitwiseOr::class => [110, -1], \PhpParser\Node\Expr\BinaryOp\BooleanAnd::class => [120, -1], \PhpParser\Node\Expr\BinaryOp\BooleanOr::class => [130, -1], \PhpParser\Node\Expr\BinaryOp\Coalesce::class => [140, 1], \PhpParser\Node\Expr\Ternary::class => [150, 0], // parser uses %left for assignments, but they really behave as %right \PhpParser\Node\Expr\Assign::class => [160, 1], \PhpParser\Node\Expr\AssignRef::class => [160, 1], \PhpParser\Node\Expr\AssignOp\Plus::class => [160, 1], \PhpParser\Node\Expr\AssignOp\Minus::class => [160, 1], \PhpParser\Node\Expr\AssignOp\Mul::class => [160, 1], \PhpParser\Node\Expr\AssignOp\Div::class => [160, 1], \PhpParser\Node\Expr\AssignOp\Concat::class => [160, 1], \PhpParser\Node\Expr\AssignOp\Mod::class => [160, 1], \PhpParser\Node\Expr\AssignOp\BitwiseAnd::class => [160, 1], \PhpParser\Node\Expr\AssignOp\BitwiseOr::class => [160, 1], \PhpParser\Node\Expr\AssignOp\BitwiseXor::class => [160, 1], \PhpParser\Node\Expr\AssignOp\ShiftLeft::class => [160, 1], \PhpParser\Node\Expr\AssignOp\ShiftRight::class => [160, 1], \PhpParser\Node\Expr\AssignOp\Pow::class => [160, 1], \PhpParser\Node\Expr\AssignOp\Coalesce::class => [160, 1], \PhpParser\Node\Expr\YieldFrom::class => [165, 1], \PhpParser\Node\Expr\Print_::class => [168, 1], \PhpParser\Node\Expr\BinaryOp\LogicalAnd::class => [170, -1], \PhpParser\Node\Expr\BinaryOp\LogicalXor::class => [180, -1], \PhpParser\Node\Expr\BinaryOp\LogicalOr::class => [190, -1], \PhpParser\Node\Expr\Include_::class => [200, -1], ]

$removalMap

protected array<string|int, array<string|int, int>> $removalMap

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.

Methods

__construct()

Creates a pretty printer instance using the given options.

public __construct([array<string|int, mixed> $options = [] ]) : mixed

Supported options:

  • bool $shortArraySyntax = false: Whether to use [] instead of array() as the default array syntax, if the node does not specify a format.
Parameters
$options : array<string|int, mixed> = []

Dictionary of formatting options

Return values
mixed

prettyPrint()

Pretty prints an array of statements.

public prettyPrint(array<string|int, Node$stmts) : string
Parameters
$stmts : array<string|int, Node>

Array of statements

Return values
string

Pretty printed statements

prettyPrintExpr()

Pretty prints an expression.

public prettyPrintExpr(Expr $node) : string
Parameters
$node : Expr

Expression node

Return values
string

Pretty printed node

prettyPrintFile()

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

public prettyPrintFile(array<string|int, Node$stmts) : string
Parameters
$stmts : array<string|int, Node>

Array of statements

Return values
string

Pretty printed statements

printFormatPreserving()

Perform a format-preserving pretty print of an AST.

public printFormatPreserving(array<string|int, Node$stmts, array<string|int, Node$origStmts, array<string|int, mixed> $origTokens) : string

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.
Parameters
$stmts : array<string|int, Node>

Modified AST with links to original AST

$origStmts : array<string|int, Node>

Original AST with token offset information

$origTokens : array<string|int, mixed>

Tokens of the original code

Return values
string

callLhsRequiresParens()

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

protected callLhsRequiresParens(Node $node) : bool
Parameters
$node : Node

LHS of a call

Return values
bool

Whether parentheses are required

containsEndLabel()

protected containsEndLabel(mixed $string, mixed $label[, mixed $atStart = true ][, mixed $atEnd = true ]) : mixed
Parameters
$string : mixed
$label : mixed
$atStart : mixed = true
$atEnd : mixed = true
Return values
mixed

dereferenceLhsRequiresParens()

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

protected dereferenceLhsRequiresParens(Node $node) : bool
Parameters
$node : Node

LHS of dereferencing operation

Return values
bool

Whether parentheses are required

encapsedContainsEndLabel()

protected encapsedContainsEndLabel(array<string|int, mixed> $parts, mixed $label) : mixed
Parameters
$parts : array<string|int, mixed>
$label : mixed
Return values
mixed

escapeString()

protected escapeString(mixed $string, mixed $quote) : mixed
Parameters
$string : mixed
$quote : mixed
Return values
mixed

handleMagicTokens()

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

protected handleMagicTokens(string $str) : string
Parameters
$str : string
Return values
string

hasNodeWithComments()

protected hasNodeWithComments(array<string|int, Node$nodes) : bool
Parameters
$nodes : array<string|int, Node>
Return values
bool

initializeEmptyListInsertionMap()

protected initializeEmptyListInsertionMap() : mixed
Return values
mixed

initializeFixupMap()

Lazily initializes fixup map.

protected initializeFixupMap() : mixed

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.

Return values
mixed

initializeInsertionMap()

protected initializeInsertionMap() : mixed
Return values
mixed

initializeLabelCharMap()

Lazily initializes label char map.

protected initializeLabelCharMap() : mixed

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

Return values
mixed

initializeListInsertionMap()

protected initializeListInsertionMap() : mixed
Return values
mixed

initializeModifierChangeMap()

protected initializeModifierChangeMap() : mixed
Return values
mixed

initializeNodeListDiffer()

Lazily initializes node list differ.

protected initializeNodeListDiffer() : mixed

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

Return values
mixed

initializeRemovalMap()

Lazily initializes the removal map.

protected initializeRemovalMap() : mixed

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

Return values
mixed

isMultiline()

Determine whether a list of nodes uses multiline formatting.

protected isMultiline(array<string|int, \PhpParser\Node|null> $nodes) : bool
Parameters
$nodes : array<string|int, \PhpParser\Node|null>

Node list

Return values
bool

Whether multiline formatting is used

p()

Pretty prints a node.

protected p(Node $node[, bool $parentFormatPreserved = false ]) : string

This method also handles formatting preservation for nodes.

Parameters
$node : Node

Node to be pretty printed

$parentFormatPreserved : bool = false

Whether parent node has preserved formatting

Return values
string

Pretty printed node

pArg()

protected pArg(Arg $node) : mixed
Parameters
$node : Arg
Return values
mixed

pArray()

Perform a format-preserving pretty print of an array.

protected pArray(array<string|int, mixed> $nodes, array<string|int, mixed> $origNodes, int &$pos, int $indentAdjustment, string $parentNodeType, string $subNodeName, null|int $fixup) : null|string
Parameters
$nodes : array<string|int, mixed>

New nodes

$origNodes : array<string|int, mixed>

Original nodes

$pos : int

Current token position (updated by reference)

$indentAdjustment : int

Adjustment for indentation

$parentNodeType : string

Type of the containing node.

$subNodeName : string

Name of array subnode.

$fixup : null|int

Fixup information for array item nodes

Return values
null|string

Result of pretty print or null if cannot preserve formatting

pAttrGroups()

protected pAttrGroups(array<string|int, mixed> $nodes[, bool $inline = false ]) : string
Parameters
$nodes : array<string|int, mixed>
$inline : bool = false
Return values
string

pCallLhs()

protected pCallLhs(Node $node) : mixed
Parameters
$node : Node
Return values
mixed

pClassCommon()

protected pClassCommon(Class_ $node, mixed $afterClassToken) : mixed
Parameters
$node : Class_
$afterClassToken : mixed
Return values
mixed

pCommaSeparated()

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

protected pCommaSeparated(array<string|int, Node$nodes) : string
Parameters
$nodes : array<string|int, Node>

Array of Nodes to be printed

Return values
string

Comma separated pretty printed nodes

pCommaSeparatedMultiline()

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

protected pCommaSeparatedMultiline(array<string|int, Node$nodes, bool $trailingComma) : string

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

Parameters
$nodes : array<string|int, Node>

Array of Nodes to be printed

$trailingComma : bool

Whether to use a trailing comma

Return values
string

Comma separated pretty printed nodes in multiline style

pComments()

Prints reformatted text of the passed comments.

protected pComments(array<string|int, Comment$comments) : string
Parameters
$comments : array<string|int, Comment>

List of comments

Return values
string

Reformatted text of comments

pDereferenceLhs()

protected pDereferenceLhs(Node $node) : mixed
Parameters
$node : Node
Return values
mixed

pEncapsList()

protected pEncapsList(array<string|int, mixed> $encapsList, mixed $quote) : mixed
Parameters
$encapsList : array<string|int, mixed>
$quote : mixed
Return values
mixed

pExpr_Array()

protected pExpr_Array(Array_ $node) : mixed
Parameters
$node : Array_
Return values
mixed

pExpr_Assign()

protected pExpr_Assign(Assign $node) : mixed
Parameters
$node : Assign
Return values
mixed

pExpr_AssignOp_BitwiseAnd()

protected pExpr_AssignOp_BitwiseAnd(BitwiseAnd $node) : mixed
Parameters
$node : BitwiseAnd
Return values
mixed

pExpr_AssignOp_BitwiseOr()

protected pExpr_AssignOp_BitwiseOr(BitwiseOr $node) : mixed
Parameters
$node : BitwiseOr
Return values
mixed

pExpr_AssignOp_BitwiseXor()

protected pExpr_AssignOp_BitwiseXor(BitwiseXor $node) : mixed
Parameters
$node : BitwiseXor
Return values
mixed

pExpr_AssignOp_Coalesce()

protected pExpr_AssignOp_Coalesce(Coalesce $node) : mixed
Parameters
$node : Coalesce
Return values
mixed

pExpr_AssignOp_Concat()

protected pExpr_AssignOp_Concat(Concat $node) : mixed
Parameters
$node : Concat
Return values
mixed

pExpr_AssignOp_Div()

protected pExpr_AssignOp_Div(Div $node) : mixed
Parameters
$node : Div
Return values
mixed

pExpr_AssignOp_Minus()

protected pExpr_AssignOp_Minus(Minus $node) : mixed
Parameters
$node : Minus
Return values
mixed

pExpr_AssignOp_Mod()

protected pExpr_AssignOp_Mod(Mod $node) : mixed
Parameters
$node : Mod
Return values
mixed

pExpr_AssignOp_Mul()

protected pExpr_AssignOp_Mul(Mul $node) : mixed
Parameters
$node : Mul
Return values
mixed

pExpr_AssignOp_Plus()

protected pExpr_AssignOp_Plus(Plus $node) : mixed
Parameters
$node : Plus
Return values
mixed

pExpr_AssignOp_Pow()

protected pExpr_AssignOp_Pow(Pow $node) : mixed
Parameters
$node : Pow
Return values
mixed

pExpr_AssignOp_ShiftLeft()

protected pExpr_AssignOp_ShiftLeft(ShiftLeft $node) : mixed
Parameters
$node : ShiftLeft
Return values
mixed

pExpr_AssignOp_ShiftRight()

protected pExpr_AssignOp_ShiftRight(ShiftRight $node) : mixed
Parameters
$node : ShiftRight
Return values
mixed

pExpr_BinaryOp_BitwiseAnd()

protected pExpr_BinaryOp_BitwiseAnd(BitwiseAnd $node) : mixed
Parameters
$node : BitwiseAnd
Return values
mixed

pExpr_BinaryOp_BitwiseOr()

protected pExpr_BinaryOp_BitwiseOr(BitwiseOr $node) : mixed
Parameters
$node : BitwiseOr
Return values
mixed

pExpr_BinaryOp_BitwiseXor()

protected pExpr_BinaryOp_BitwiseXor(BitwiseXor $node) : mixed
Parameters
$node : BitwiseXor
Return values
mixed

pExpr_BinaryOp_BooleanAnd()

protected pExpr_BinaryOp_BooleanAnd(BooleanAnd $node) : mixed
Parameters
$node : BooleanAnd
Return values
mixed

pExpr_BinaryOp_BooleanOr()

protected pExpr_BinaryOp_BooleanOr(BooleanOr $node) : mixed
Parameters
$node : BooleanOr
Return values
mixed

pExpr_BinaryOp_Coalesce()

protected pExpr_BinaryOp_Coalesce(Coalesce $node) : mixed
Parameters
$node : Coalesce
Return values
mixed

pExpr_BinaryOp_Concat()

protected pExpr_BinaryOp_Concat(Concat $node) : mixed
Parameters
$node : Concat
Return values
mixed

pExpr_BinaryOp_Div()

protected pExpr_BinaryOp_Div(Div $node) : mixed
Parameters
$node : Div
Return values
mixed

pExpr_BinaryOp_Equal()

protected pExpr_BinaryOp_Equal(Equal $node) : mixed
Parameters
$node : Equal
Return values
mixed

pExpr_BinaryOp_Greater()

protected pExpr_BinaryOp_Greater(Greater $node) : mixed
Parameters
$node : Greater
Return values
mixed

pExpr_BinaryOp_Identical()

protected pExpr_BinaryOp_Identical(Identical $node) : mixed
Parameters
$node : Identical
Return values
mixed

pExpr_BinaryOp_LogicalAnd()

protected pExpr_BinaryOp_LogicalAnd(LogicalAnd $node) : mixed
Parameters
$node : LogicalAnd
Return values
mixed

pExpr_BinaryOp_LogicalOr()

protected pExpr_BinaryOp_LogicalOr(LogicalOr $node) : mixed
Parameters
$node : LogicalOr
Return values
mixed

pExpr_BinaryOp_LogicalXor()

protected pExpr_BinaryOp_LogicalXor(LogicalXor $node) : mixed
Parameters
$node : LogicalXor
Return values
mixed

pExpr_BinaryOp_Minus()

protected pExpr_BinaryOp_Minus(Minus $node) : mixed
Parameters
$node : Minus
Return values
mixed

pExpr_BinaryOp_Mod()

protected pExpr_BinaryOp_Mod(Mod $node) : mixed
Parameters
$node : Mod
Return values
mixed

pExpr_BinaryOp_Mul()

protected pExpr_BinaryOp_Mul(Mul $node) : mixed
Parameters
$node : Mul
Return values
mixed

pExpr_BinaryOp_NotEqual()

protected pExpr_BinaryOp_NotEqual(NotEqual $node) : mixed
Parameters
$node : NotEqual
Return values
mixed

pExpr_BinaryOp_Plus()

protected pExpr_BinaryOp_Plus(Plus $node) : mixed
Parameters
$node : Plus
Return values
mixed

pExpr_BinaryOp_Pow()

protected pExpr_BinaryOp_Pow(Pow $node) : mixed
Parameters
$node : Pow
Return values
mixed

pExpr_BinaryOp_ShiftLeft()

protected pExpr_BinaryOp_ShiftLeft(ShiftLeft $node) : mixed
Parameters
$node : ShiftLeft
Return values
mixed

pExpr_BinaryOp_ShiftRight()

protected pExpr_BinaryOp_ShiftRight(ShiftRight $node) : mixed
Parameters
$node : ShiftRight
Return values
mixed

pExpr_BinaryOp_Smaller()

protected pExpr_BinaryOp_Smaller(Smaller $node) : mixed
Parameters
$node : Smaller
Return values
mixed

pExpr_BinaryOp_Spaceship()

protected pExpr_BinaryOp_Spaceship(Spaceship $node) : mixed
Parameters
$node : Spaceship
Return values
mixed

pExpr_Cast_Array()

protected pExpr_Cast_Array(Array_ $node) : mixed
Parameters
$node : Array_
Return values
mixed

pExpr_Cast_Bool()

protected pExpr_Cast_Bool(Bool_ $node) : mixed
Parameters
$node : Bool_
Return values
mixed

pExpr_Cast_Double()

protected pExpr_Cast_Double(Double $node) : mixed
Parameters
$node : Double
Return values
mixed

pExpr_Cast_Int()

protected pExpr_Cast_Int(Int_ $node) : mixed
Parameters
$node : Int_
Return values
mixed

pExpr_Cast_Object()

protected pExpr_Cast_Object(Object_ $node) : mixed
Parameters
$node : Object_
Return values
mixed

pExpr_Cast_String()

protected pExpr_Cast_String(String_ $node) : mixed
Parameters
$node : String_
Return values
mixed

pExpr_Cast_Unset()

protected pExpr_Cast_Unset(Unset_ $node) : mixed
Parameters
$node : Unset_
Return values
mixed

pExpr_Clone()

protected pExpr_Clone(Clone_ $node) : mixed
Parameters
$node : Clone_
Return values
mixed

pExpr_Closure()

protected pExpr_Closure(Closure $node) : mixed
Parameters
$node : Closure
Return values
mixed

pExpr_Empty()

protected pExpr_Empty(Empty_ $node) : mixed
Parameters
$node : Empty_
Return values
mixed

pExpr_Error()

protected pExpr_Error(Error $node) : mixed
Parameters
$node : Error
Return values
mixed

pExpr_Eval()

protected pExpr_Eval(Eval_ $node) : mixed
Parameters
$node : Eval_
Return values
mixed

pExpr_Exit()

protected pExpr_Exit(Exit_ $node) : mixed
Parameters
$node : Exit_
Return values
mixed

pExpr_Isset()

protected pExpr_Isset(Isset_ $node) : mixed
Parameters
$node : Isset_
Return values
mixed

pExpr_List()

protected pExpr_List(List_ $node) : mixed
Parameters
$node : List_
Return values
mixed

pExpr_Match()

protected pExpr_Match(Match_ $node) : mixed
Parameters
$node : Match_
Return values
mixed

pExpr_New()

protected pExpr_New(New_ $node) : mixed
Parameters
$node : New_
Return values
mixed

pExpr_PostDec()

protected pExpr_PostDec(PostDec $node) : mixed
Parameters
$node : PostDec
Return values
mixed

pExpr_PostInc()

protected pExpr_PostInc(PostInc $node) : mixed
Parameters
$node : PostInc
Return values
mixed

pExpr_PreDec()

protected pExpr_PreDec(PreDec $node) : mixed
Parameters
$node : PreDec
Return values
mixed

pExpr_PreInc()

protected pExpr_PreInc(PreInc $node) : mixed
Parameters
$node : PreInc
Return values
mixed

pExpr_Print()

protected pExpr_Print(Print_ $node) : mixed
Parameters
$node : Print_
Return values
mixed

pExpr_Ternary()

protected pExpr_Ternary(Ternary $node) : mixed
Parameters
$node : Ternary
Return values
mixed

pExpr_Throw()

protected pExpr_Throw(Throw_ $node) : mixed
Parameters
$node : Throw_
Return values
mixed

pExpr_Yield()

protected pExpr_Yield(Yield_ $node) : mixed
Parameters
$node : Yield_
Return values
mixed

pFixup()

Print node with fixups.

protected pFixup(int $fixup, Node $subNode, string|null $parentClass, int $subStartPos, int $subEndPos) : string

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).

Parameters
$fixup : int

Fixup type

$subNode : Node

Subnode to print

$parentClass : string|null

Class of parent node

$subStartPos : int

Original start pos of subnode

$subEndPos : int

Original end pos of subnode

Return values
string

Result of fixed-up print of subnode

pImplode()

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

protected pImplode(array<string|int, Node$nodes[, string $glue = '' ]) : string
Parameters
$nodes : array<string|int, Node>

Array of Nodes to be printed

$glue : string = ''

Character to implode with

Return values
string

Imploded pretty printed nodes

pInfixOp()

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

protected pInfixOp(string $class, Node $leftNode, string $operatorString, Node $rightNode) : string
Parameters
$class : string

Node class of operator

$leftNode : Node

Left-hand side node

$operatorString : string

String representation of the operator

$rightNode : Node

Right-hand side node

Return values
string

Pretty printed infix operation

pMaybeMultiline()

protected pMaybeMultiline(array<string|int, mixed> $nodes[, bool $trailingComma = false ]) : mixed
Parameters
$nodes : array<string|int, mixed>
$trailingComma : bool = false
Return values
mixed

pModifiers()

Print modifiers, including trailing whitespace.

protected pModifiers(int $modifiers) : string
Parameters
$modifiers : int

Modifier mask to print

Return values
string

Printed modifiers

pName()

protected pName(Name $node) : mixed
Parameters
$node : Name
Return values
mixed

pNewVariable()

protected pNewVariable(Node $node) : mixed
Parameters
$node : Node
Return values
mixed

pObjectProperty()

protected pObjectProperty(mixed $node) : mixed
Parameters
$node : mixed
Return values
mixed

pParam()

protected pParam(Param $node) : mixed
Parameters
$node : Param
Return values
mixed

pPostfixOp()

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

protected pPostfixOp(string $class, Node $node, string $operatorString) : string
Parameters
$class : string

Node class of operator

$node : Node

Node

$operatorString : string

String representation of the operator

Return values
string

Pretty printed postfix operation

pPrec()

Prints an expression node with the least amount of parentheses necessary to preserve the meaning.

protected pPrec(Node $node, int $parentPrecedence, int $parentAssociativity, int $childPosition) : string
Parameters
$node : Node

Node to pretty print

$parentPrecedence : int

Precedence of the parent operator

$parentAssociativity : int

Associativity of parent operator (-1 is left, 0 is nonassoc, 1 is right)

$childPosition : int

Position of the node relative to the operator (-1 is left, 1 is right)

Return values
string

The pretty printed node

pPrefixOp()

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

protected pPrefixOp(string $class, string $operatorString, Node $node) : string
Parameters
$class : string

Node class of operator

$operatorString : string

String representation of the operator

$node : Node

Node

Return values
string

Pretty printed prefix operation

preprocessNodes()

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

protected preprocessNodes(array<string|int, Node$nodes) : mixed
Parameters
$nodes : array<string|int, Node>

Array of nodes

Return values
mixed

pScalar_DNumber()

protected pScalar_DNumber(DNumber $node) : mixed
Parameters
$node : DNumber
Return values
mixed

pScalar_Encapsed()

protected pScalar_Encapsed(Encapsed $node) : mixed
Parameters
$node : Encapsed
Return values
mixed

pScalar_LNumber()

protected pScalar_LNumber(LNumber $node) : mixed
Parameters
$node : LNumber
Return values
mixed

pScalar_MagicConst_Class()

protected pScalar_MagicConst_Class(Class_ $node) : mixed
Parameters
$node : Class_
Return values
mixed

pScalar_MagicConst_Dir()

protected pScalar_MagicConst_Dir(Dir $node) : mixed
Parameters
$node : Dir
Return values
mixed

pScalar_MagicConst_File()

protected pScalar_MagicConst_File(File $node) : mixed
Parameters
$node : File
Return values
mixed

pScalar_MagicConst_Function()

protected pScalar_MagicConst_Function(Function_ $node) : mixed
Parameters
$node : Function_
Return values
mixed

pScalar_MagicConst_Line()

protected pScalar_MagicConst_Line(Line $node) : mixed
Parameters
$node : Line
Return values
mixed

pScalar_MagicConst_Method()

protected pScalar_MagicConst_Method(Method $node) : mixed
Parameters
$node : Method
Return values
mixed

pScalar_MagicConst_Namespace()

protected pScalar_MagicConst_Namespace(Namespace_ $node) : mixed
Parameters
$node : Namespace_
Return values
mixed

pScalar_MagicConst_Trait()

protected pScalar_MagicConst_Trait(Trait_ $node) : mixed
Parameters
$node : Trait_
Return values
mixed

pScalar_String()

protected pScalar_String(String_ $node) : mixed
Parameters
$node : String_
Return values
mixed

pSingleQuotedString()

protected pSingleQuotedString(string $string) : mixed
Parameters
$string : string
Return values
mixed

pStmt_Break()

protected pStmt_Break(Break_ $node) : mixed
Parameters
$node : Break_
Return values
mixed

pStmt_Case()

protected pStmt_Case(Case_ $node) : mixed
Parameters
$node : Case_
Return values
mixed

pStmt_Catch()

protected pStmt_Catch(Catch_ $node) : mixed
Parameters
$node : Catch_
Return values
mixed

pStmt_Class()

protected pStmt_Class(Class_ $node) : mixed
Parameters
$node : Class_
Return values
mixed

pStmt_Const()

protected pStmt_Const(Const_ $node) : mixed
Parameters
$node : Const_
Return values
mixed

pStmt_Do()

protected pStmt_Do(Do_ $node) : mixed
Parameters
$node : Do_
Return values
mixed

pStmt_Echo()

protected pStmt_Echo(Echo_ $node) : mixed
Parameters
$node : Echo_
Return values
mixed

pStmt_Else()

protected pStmt_Else(Else_ $node) : mixed
Parameters
$node : Else_
Return values
mixed

pStmt_ElseIf()

protected pStmt_ElseIf(ElseIf_ $node) : mixed
Parameters
$node : ElseIf_
Return values
mixed

pStmt_Enum()

protected pStmt_Enum(Enum_ $node) : mixed
Parameters
$node : Enum_
Return values
mixed

pStmt_For()

protected pStmt_For(For_ $node) : mixed
Parameters
$node : For_
Return values
mixed

pStmt_Global()

protected pStmt_Global(Global_ $node) : mixed
Parameters
$node : Global_
Return values
mixed

pStmt_Goto()

protected pStmt_Goto(Goto_ $node) : mixed
Parameters
$node : Goto_
Return values
mixed

pStmt_If()

protected pStmt_If(If_ $node) : mixed
Parameters
$node : If_
Return values
mixed

pStmt_Label()

protected pStmt_Label(Label $node) : mixed
Parameters
$node : Label
Return values
mixed

pStmt_Nop()

protected pStmt_Nop(Nop $node) : mixed
Parameters
$node : Nop
Return values
mixed

pStmt_Return()

protected pStmt_Return(Return_ $node) : mixed
Parameters
$node : Return_
Return values
mixed

pStmt_Static()

protected pStmt_Static(Static_ $node) : mixed
Parameters
$node : Static_
Return values
mixed

pStmt_Switch()

protected pStmt_Switch(Switch_ $node) : mixed
Parameters
$node : Switch_
Return values
mixed

pStmt_Throw()

protected pStmt_Throw(Throw_ $node) : mixed
Parameters
$node : Throw_
Return values
mixed

pStmt_Trait()

protected pStmt_Trait(Trait_ $node) : mixed
Parameters
$node : Trait_
Return values
mixed

pStmt_TraitUseAdaptation_Alias()

protected pStmt_TraitUseAdaptation_Alias(Alias $node) : mixed
Parameters
$node : Alias
Return values
mixed

pStmt_TraitUseAdaptation_Precedence()

protected pStmt_TraitUseAdaptation_Precedence(Precedence $node) : mixed
Parameters
$node : Precedence
Return values
mixed

pStmt_Unset()

protected pStmt_Unset(Unset_ $node) : mixed
Parameters
$node : Unset_
Return values
mixed

pStmt_Use()

protected pStmt_Use(Use_ $node) : mixed
Parameters
$node : Use_
Return values
mixed

pStmt_UseUse()

protected pStmt_UseUse(UseUse $node) : mixed
Parameters
$node : UseUse
Return values
mixed

pStmt_While()

protected pStmt_While(While_ $node) : mixed
Parameters
$node : While_
Return values
mixed

pStmts()

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

protected pStmts(array<string|int, Node$nodes[, bool $indent = true ]) : string
Parameters
$nodes : array<string|int, Node>

Array of nodes

$indent : bool = true

Whether to indent the printed nodes

Return values
string

Pretty printed statements

pUseType()

protected pUseType(mixed $type) : mixed
Parameters
$type : mixed
Return values
mixed

resetState()

Reset pretty printing state.

protected resetState() : mixed
Return values
mixed

safeAppend()

Appends to a string, ensuring whitespace between label characters.

protected safeAppend(string &$str, string $append) : mixed

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.

Parameters
$str : string
$append : string
Return values
mixed

setIndentLevel()

Set indentation level

protected setIndentLevel(int $level) : mixed
Parameters
$level : int

Level in number of spaces

Return values
mixed

Search results