Node Reference
A reference of all node classes: what each one is, its slots with their types, and its public properties and
methods. A slot is named by its role, not by its text (ifKeyword, openParen, body), paired
delimiters are always open* and close*, a list of nodes has a plural name (statements,
members), and ? marks a slot that may be empty.
The classes live in PhpSyntax\Nodes and its sub-namespaces Statement, Expression,
Member, Scalar and Type; names in types are written relative to
PhpSyntax\Nodes (Expression\VariableNode), classes outside it relative to PhpSyntax
(Token). A slot of type Token holds one token, PlainNodeList<T> a list of nodes
without separators, and SeparatedNodeList<T> a list with separators between the items: commas, vertical bars in
union types and in catch, and ampersands in intersection types. Both lists are subtypes of
NodeList<T>. For each class, the slots come first, then the constants, properties and methods the class adds
itself; what every node can do is listed under Node, what every expression can do under ExpressionNode.
The descriptions are taken from the doc comments in the code. The pages Nodes and
Slots and Modifying the Tree explain how to read and change
the tree.
Base Classes and Interfaces
The ancestor classes and interfaces you use to search for and filter nodes
($file->find(ExpressionNode::class)). Node lives in PhpSyntax,
TraitAdaptationNode in PhpSyntax\Nodes\Member, and the others in PhpSyntax\Nodes.
Node
Node of the concrete syntax tree; every token of the source is reachable through the children. The nodes and the lists are the library's own: a class extending one or implementing an interface of the nodes elsewhere is not supported, so the protected members, the machinery of the writes, are internal.
$parent: ?Node– The node this one belongs to; only the tree writes it.$text: string– The node as it is written, without the trivia on its outer edges, which printing it writes too.$leadingTrivia: list<Trivia>– The trivia before the node, which are the leading trivia of its first token;setEdgeTrivia()writes them.$trailingTrivia: list<Trivia>– The trivia after the node, which are the trailing trivia of its last token;setEdgeTrivia()writes them.getChildren(): list<Node|Token>– Children in source order, without empty slots.replaceChild(Node|Token $old, Node|Token $new): void– Replaces a direct child; the new one must fit the type of the slot.findSlotOf(Node|Token $child): ?string– The slot the direct child stands in; null when it is not a child. A list andModifiersNodeanswer with the collection their child is in,items,separatorsortokens, which is read, not a slot to write.getFile(): ?FileNodegetTokens(): list<Token>– The tokens of the whole subtree in source order; empty for a node without tokens, such as an empty list.getTokenTexts(): list<string>– The texts of the tokens of the subtree in source order, the trivia left out: whatmatches()compares two nodes by, and what a tool keys a map by where the layout of the code must not count. The size of the code is measured on$text, which keeps the layout.getFirstToken(): ?Token– Null only for a node without tokens.getLastToken(): ?TokengetStartLine(): ?int– Current line of the first token; null for a detached subtree or a node without tokens.getEndLine(): ?int– Current line where the last token ends; null as forgetStartLine().isMultiLine(): bool– Whether a line ends inside the text of the node, the trivia on its outer edges left out; unlike the lines, it needs no file.getOffsetRange(): ?array{int, int}– Byte offsets of the node in the current text of the file, the end exclusive; null as forgetStartLine().getDocComment(): ?Trivia– Doc comment before the node: the last one in the leading trivia of the first token, or in the trailing trivia of the previous token, where a doc comment stands between two declarations on one line; one inside string interpolation is left out, documenting nothing there.replaceTrivia(Trivia $old, Trivia $new): void– Replaces one trivia of the node, wherever among its tokens it stands, with another in place.removeTrivia(Trivia $trivia): void– Removes one trivia of the node, wherever among its tokens it stands, tidying the whitespace around it the wayToken::removeTrivia()does.replaceDocComment(Trivia $docComment): void– Replaces the doc comment of the node (seegetDocComment()) with the trivia given.removeDocComment(): void– Removes the doc comment of the node (seegetDocComment()) together with the line it stands on.findAncestor(class-string<T> $class): (T&Node)|null– The innermost node of the class above this one, its parent first.findClassScope(): (ClassLikeNode&Node)|null– The class whose scope the node stands in, the oneself,staticand__CLASS__name; null outside a class and in a function declared inside a method, which has no class scope. The arguments ofnew class(...)stand in the scope around it.findFirst(class-string<T> $class, ?callable $predicate = null): (T&Node)|null– The first descendant of the class the predicate accepts, in pre-order; null when there is none.find(class-string<T> $class, ?callable $predicate = null): list<T&Node>– Descendant nodes of the class the predicate accepts, in pre-order, as a snapshot safe to iterate while mutating the tree.getNextSibling(): ?Node– The next item of the list the node is an item of; null for the last one.getPreviousSibling(): ?Node– The previous item of the list the node is an item of; null for the first one.matches(Node $other): bool– Whether the tokens of both nodes carry the same texts, whatever the whitespace between them.hasInnerComment(): bool– Whether a comment sits anywhere between the first and the last token of the node; the trivia on its outer edges do not count.getInnerComments(): list<Trivia>– The comments inside the node, in source order; those on its outer edges are not among them, the same wayhasInnerComment()does not count them.hasLeadingComment(): bool– Whether a comment sits on the leading edge of the node, among the trivia before its first token.hasTrailingComment(): bool– Whether a comment sits on the trailing edge of the node, among the trivia after its last token.getLeadingComments(): list<Trivia>– The comments on the leading edge of the node, before its first token.getTrailingComments(): list<Trivia>– The comments on the trailing edge of the node, after its last token up to the end of its line.setEdgeTrivia(?list<Trivia> $leading = null, ?list<Trivia> $trailing = null): static– Writes the trivia on the outer edges of the node: before its first token and after its last one. Anullleaves that edge alone,[]clears it, and a node without tokens takes neither.withoutEdgeTrivia(): static– A deep copy without a parent and without the trivia on its outer edges, which belong to the place it was copied from.replaceWith(Node $node): void– Replaces this node in its parent; the trivia around the old node stay in place around the new one, or with the tokens on either side when the new one has no tokens, an empty list, and where the new one then stands right against a token it would be read together with,.against1orreturnagainstFOO, a space keeps the two apart.remove(CommentPolicy $comments = CommentPolicy::MoveToNextToken, bool $mergeBlankLines = false): void– Removes this node from its list, together with the separator that goes with it. A node alone on its lines takes the lines with it (indentation and line ending), otherwise the whitespace around stays; the comments it owns, inside it, on its line, its doc comment and the ones right above it, go where the policy says, each with its indentation and the line ending after it, while a comment above set apart by a blank line stays where it is. With$mergeBlankLines, where the node and the token after it stand at the start of a line, the two gaps of blank lines the node stood between become the narrower of them, or the one toward the edge where the node was the first or the last item of its list, counted above the comments the node leaves behind.__toString(): string– The node printed back to source, the trivia on its outer edges included;$textleaves them out.
AnonymousFunctionNode
Function written as an expression, without a name: closure, arrow function; an interface, because the two share no base class
but the expression. Extends FunctionLikeNode, AttributeAwareNode.
$staticKeyword: ?Token
AttributeAwareNode
Declaration that may carry attributes, its list empty where none is written: a class-like or a function-like one, a member, a constant, an enum case, a parameter; an interface, because they share no base class.
$attributes: PlainNodeList<AttributeGroupNode>
ClassLikeNode
Declaration with members: class, interface, trait, enum, anonymous class; an interface, because an anonymous class stands
inside a new expression and the rest are statements. Extends AttributeAwareNode.
$name: ?IdentifierNode$members: PlainNodeList<MemberNode>
ExpressionNode
Expression, which stands for a value; a destructuring stands where a target is written and is a DestructuringNode, not one of
these. Extends Node.
getDereferenceKind(): ?DereferenceKind– How the parent reaches into this expression, null where it does not:$this->x,$this->y()and$this[0]fetch from it,$this()calls it,$this::y()takes it for the name of a class.isDereferenced(): bool– Whether the parent reads a member, an element or a static member of this expression, or calls it:$this->x,$this[0],$this::y(),$this(). Such an expression needs parentheses unless the grammar makes it a primary one.isDereferenceable(DereferenceKind $by = DereferenceKind::Fetch): bool– Whether what is written after the expression may reach into it with no parentheses around it. A call takes a name or a member written before it for its own, which calls another thing entirely, and::takes the name of a class, which a name written there would become.canStandInString(): bool– Whether the expression may be written inside a double-quoted string, a heredoc or a shell command in braces,{$...}: what the grammar reads as a variable there, which is a variable, an element, a property, a static property or a call of a function, a method or a static method, starting with the dollar of a variable.isWritable(): bool– Whether the expression may stand where a place is assigned to: a variable, an element, a property, reached through a chain PHP writes through. A?->anywhere along it rules the write out, a call in the chain included, and so does a chain starting at a value of its own, a literal, a constant,neworclone, which has no place to write to. It says nothing about reading; that isisRepeatableRead(), and the two answer for the two sides of=.isInNullsafeChain(): bool– Whether a?->stands in the chain the expression reads out of, its own access and parentheses included: PHP refuses to write there or to make a first-class callable of a call there, the?->possibly skipping the rest.isWritten(): bool– Whether something writes the expression or an element of it, a variable, a property or an element alike: it is assigned, stepped, unset, bound, or taken by reference, either side of=&among them, the right one becoming a reference a write may later go through.isRepeatableRead(): bool– Whether reading the expression again gives the same value with no side effects: variables, property, constant and offset fetches, literals, arrays of such items and what parentheses or a unary operator make of them, nothing that runs code of its own; an unpacked item may run a generator and one by reference creates the variable, so neither is repeatable. The answer is syntactic, so what the language runs behind such a read is out of sight and does not count: a magic getter or a property hook behind a fetch, anArrayAccessbehind an offset, a__toString()behind a string that interpolates, and the error of a property read before it is initialized. Whoever cannot assume that much has to know the types, which a syntax tree does not. The same value holds only while nothing runs between the reads: a call evaluated between them may change a property or an offset, never a variable it is not given.hasEffect(): bool– Whether evaluating the expression may do more than give its value: call code, create or clone an object, write, print, leave or run a command; a closure or an arrow function written in it counts by the expressions of its body, though making one runs nothing. The answer is syntactic as that ofisRepeatableRead(), so a read an object answers through a magic method or a hook does not count, and neither does what may fail, an error a division by zero throws or a warning a read of a missing key gives.isConstantRead(): bool– Whether the expression reads a constant, global or of a class named outright, the same whenever it is read.isConstantExpression(ConstantExpressionFeature ...$allowed): bool– Whether the expression may stand where PHP asks for a constant expression, holding nothing beyond what every place and every version takes but the features allowed: literals, constants,X::CandX::classother than ofstatic, the operators but the pipe, the ternary, arrays and offsets into them. What PHP takes in some versions and no feature names, a property of an enum case or a class constant named by an expression, counts as none.hasEarlyReads(): bool– Whether PHP reads a part of the expression, the target of an assignment, before it evaluates the value: an offset or a name that is neither a plain variable, a literal nor a constant, or a class given by an expression,$a[$o->i] = $o->next()reading$o->ibefore the call.evaluatesToBoolean(): bool– Whether the expression yields a boolean whatever its operands: a comparison, a logical operation, a negation,instanceof,isset(),empty(), a bool cast or a boolean literal.toValue(): mixed– The value the expression is written as: a scalar,null,true,false, or an array of them. A name standing for a constant is not one, its value being a matter of what the code around it defines. ThrowsLogicExceptionwhere the expression is written as no value;hasValue()tells beforehand.hasValue(): bool– Whether the expression is written as a value, which is whattoValue()gives.replaceWithExpression(ExpressionNode $expression): void– Replaces this node by the expression the wayreplaceWith()does, in parentheses where the expression binds looser than the place asks or is reached into there: whatParenthesizedNode::isRedundant()does not call needless stays. A place typed narrower, which takes no parentheses, gets the expression bare. The name of a member or of a variable written as a bare variable ($o->$m,A::$m,$$m) takes a variable bare and anything else in braces ($o->{$a . 'b'}), which is what the grammar reads there. Inside a string, a heredoc or a shell command the grammar of interpolation decides. What begins the expression of{$...}takes only an expression thatcanStandInString(), written as it is, and so does a part standing bare among the parts of the string, in braces where the bare form would read it otherwise; a place inside a bare part keeps the bare form for a plain variable and turns the part into{$...}for anything else. The name of${name}is refused, an expression there naming a variable variable, and so are braces that would follow a dollar of the text and read as${. The trivia the expression brings are marked as standing in the string, and outside a string they lose such a mark, but for those inside a string the expression holds. ThrowsInvalidArgumentExceptionfor an expression the place cannot hold, before anything moves, ascheckReplaceWithExpression()tells beforehand.checkReplaceWithExpression(ExpressionNode $expression): void– The dry run ofreplaceWithExpression(): throws what the write would refuse the expression with, and moves nothing. A slot that does not take it is refused, a place in a string it cannot stand in, braces after a dollar of the text and the name of${name}. ThrowsInvalidArgumentExceptionfor an expression the place cannot hold. ThrowsLogicExceptionfor a node without a parent and an expression the write cannot take from where it stands.
FunctionLikeNode
Declaration with parameters and a body: function, method, closure, arrow function, property hook; an interface, because a
closure and an arrow function are expressions and the rest are not. Extends AttributeAwareNode.
$ampersand: ?Token– The&by which the declaration returns a reference, that of&getamong them; null where none is.$openParen: ?Token– The parenthesis opening the parameters; null for a property hook written without parentheses.$parameters: ?SeparatedNodeList<ParameterNode>– Null for a property hook written without parentheses.$closeParen: ?Token– The parenthesis closing the parameters; null for a property hook written without parentheses.$returnType: ?TypeNode– The return type declared; null where none is, a property hook having none to declare.setReturnType(?TypeNode $type): static– Writes the return type together with its colon, or removes both, their comments staying after the closing parenthesis; the gap before the body stays where it was, and a type standing in a tree comes as a copy without the trivia on its edges. ThrowsLogicExceptionfor a property hook, which has no return type.
MemberNode
Member of a class-like declaration: property, constant, method, trait use, enum case. Extends Node.
NodeList
Sequence of nodes, plain or separated by tokens. It has no slots and reads its items itself, and it is read as a collection:
iterated, counted and indexed ($list[0]), getItems() giving the items as an array. It changes only
through its own methods. Extends Node. Implements Countable, IteratorAggregate,
ArrayAccess. The item type T is a subtype of Node.
getItems(): list<T>isEmpty(): boolappend(T $item): voidinsert(int $index, T $item): void– Inserts an item at the index.insertAfter(Node $item, T $new): void– Inserts the new item right after the item, asinsert()does.insertBefore(Node $item, T $new): void– Inserts the new item right before the item, asinsert()does.removeItem(Node $item): void– Takes the item out with its trivia and tidies nothing;Node::remove()takes the lines with it.indexOf(Node $item): intcount(): intgetIterator(): ArrayIterator<int, T>– The items, as a snapshot safe to iterate while mutating the list.offsetExists(mixed $offset): booloffsetGet(mixed $offset): ToffsetSet(mixed $offset, mixed $value): neveroffsetUnset(mixed $offset): nevergetFirstToken(): ?Token– Null only for an empty list.
OperatorNode
Expression written with an operator, which is what decides whether parentheses around it are needed. Those whose right operand reaches as far as the code lets it, an arrow function among them, are a RightExtendingNode.
$precedence: int– How tightly the operator binds, the higher the tighter, in the order the precedence declarations of the grammar put the operators; only the order of the numbers is meant, not their values.$associativity: Associativity– Which side the operator leans to, where an operand of the same precedence may stand.
RightExtendingNode
Operator written with no left operand, whose right one reaches as far as the code lets it: fn() => …,
throw, print, yield, yield from and include. It can capture
nothing before itself, so it stands bare however loosely it binds, unless an operator follows it, which its operand would take in;
before one it needs parentheses. Extends OperatorNode.
ScalarNode
Literal written in the source: a number, a string in any of its delimiters, an interpolated string, a boolean, null and a magic
constant. What it stands for is hasValue() and toValue(), which an interpolating string and a magic
constant answer no to, standing for what the code around them says. Extends ExpressionNode.
StatementNode
Statement: what a file, a block and the body of a control structure consist of. Extends Node.
remove(CommentPolicy $comments = CommentPolicy::MoveToNextToken, bool $mergeBlankLines = false): void– Removes the statement asNode::remove()does. A statement ended by a close tag leaves the tag behind as an empty statement, so that the text after it stays text. A statement that opens its code too, as<?=does, goes whole, and so does the empty statement of a close tag, whose removal is for the caller to decide.interruptsFlow(): bool– Whether the code does not go on after the statement:return,break,continue,goto,throworexit. It reads the statement itself, so anifwhose every branch returns is no such statement; that is control flow.alwaysLeaves(): bool– Whether the code never goes on past the statement: it interrupts the flow itself, or so does the last statement of a block, every branch of anifwith anelse, or every way through atry.
TraitAdaptationNode
What a trait use says about a method it takes from a trait: an alias or a precedence. The trait slot is left to the two
subclasses, an alias being able to leave it out where a precedence has to name it. Extends Node.
$method: IdentifierNode$semicolon: Token
TypeNode
Type written in a declaration: a name, a nullable, a union or an intersection. Extends Node.
isNullable(): bool– Whether the type accepts null:?T, a union withnull, andmixed.
Common Nodes
The root of the file, names, lists, parameters, arguments, attributes, parts of control structures and destructuring; they live
directly in PhpSyntax\Nodes. DestructuringNode is not an expression, because it stands only where
something is assigned to, and it has no value.
NameNode
Name of a class, function, constant or namespace: one token of any kind, a keyword included (static,
array, readonly). Extends Node.
token:Token$text: string– The name as it is written, the leading backslash and thenamespaceprefix included. Writing it replaces the token with the one the name is written as, so that a qualified name does not stay an identifier; the trivia around it and its place in the original file stay with it.$form: NameForm$parts: list<string>– Segments of the name without the leading backslash or thenamespaceprefix.$shortName: string– The last segment, which is what an import of the name brings in.$symbolKind: SymbolKind– Which table of names the name belongs to: functions when called, constants when fetched, what a use item imports, otherwise classes, a namespace among them. It follows the place in the tree, so moving the node changes it, and it says nothing about whether the name refers to a symbol or declares one, which isisReference(): whoever resolves names asks that first.static fromText(string $text): NameNode– A name written as the text, in the token the name is written as (Foo,A\B,\A\B,namespace\B); a keyword passes as well, the grammar taking one as a name in some places, whether or not it can name a symbol here.static tryFromText(string $text): ?NameNode– A name written as the text asfromText()makes it; null where the text is no name.isKeyword(): bool– Whether the name is a keyword the grammar accepts in place of a name (static,array,readonly,exit…).isSpecialClass(): bool– Whether the name isself,staticorparent, which stand for a class only where they are written.isDeclaration(): bool– Whether the name declares or imports a symbol instead of referring to one: a namespace statement or a use.isReference(): bool– Whether the name refers to a symbol of its table, one the resolver looks up: not the name auseor anamespacestatement introduces, notself,staticorparentwhere a class is named, which stand for one only where they are written, and not a builtin type where a type is written. A keyword read as a name refers where it stands for a symbol, asreadonly(...)calls a function of that name, and so doesself()or the constantparent.equals(string $name): bool– Whether the name is written the same, letter case aside where PHP ignores it: a constant is compared exactly, its namespace too, although PHP ignores the case there; a class, a function and a namespace are not. The leading backslash is part of the writing and so part of the comparison; whether two names mean the same class is what NameResolver answers.
IdentifierNode
Identifier of a declaration, member, label, hook, alias or named argument: one token of any kind, including keywords. Extends
Node.
token:Token$text: string– The identifier as it is written; whether its letter case matters is up to what it names, whichequals()knows. Writing it takes an identifier and nothing else, so that no whitespace ends up in the text of a token.static fromText(string $text): IdentifierNode– An identifier written as the text, which takes an identifier and nothing else.equals(string $name): bool– Whether the identifier is written the same, letter case aside where PHP ignores it, which it does for what names a function, a method, a class and their kin, and forclassafter::; a property, a constant, an enum case, a label and a named argument are compared exactly, and so is an identifier standing nowhere.
ArgumentListNode
Parenthesized arguments of a call, instantiation, attribute or exit. Extends Node.
openParen:Tokenitems:SeparatedNodeList<ArgumentNode|VariadicPlaceholderNode|ArgumentPlaceholderNode>closeParen:TokenisPartialApplication(): bool– Whether the list leaves parameters unbound with?or..., which makes a closure of the call instead of calling it.getPlainValues(): ?list<ExpressionNode>– The values of the arguments, in order; null where one is named, passed by reference, unpacked or a placeholder, which makes no plain list of values.findArgument(?string $name, ?int $position): ?ArgumentNode– The argument the parameter of the name and the position gets: the one written with the name, else the one standing at the position, so thatget_class(object: $o)reads as the callget_class($o)is. Null where the parameter gets none, and where the call does not say which it gets: a?placeholder holds a place without being an argument, and an unpacked array stands for as many arguments as it holds, so it takes the answer from a position after it, never from a name, which stands for itself. Whoever knows only one of the two asks with null for the other: the position alone finds no argument written with a name, the name alone none that is not.
ArgumentNode
Argument of a call: optionally named, by reference or unpacked. Extends Node.
name:?IdentifierNodecolon:?Tokenampersand:?Tokenellipsis:?Tokenvalue:ExpressionNode
VariadicPlaceholderNode
The ... placeholder of a first-class callable or a partial application: f(...),
f($a, ...). Extends Node.
ellipsis:Token
ArgumentPlaceholderNode
The ? placeholder of a partial function application, optionally named: f(?), f(name: ?).
Extends Node.
name:?IdentifierNodecolon:?Tokenquestion:Token
ParameterNode
Parameter of a function, method, closure, arrow function or hook; with modifiers it promotes a property. Extends
Node. Implements AttributeAwareNode.
attributes:PlainNodeList<AttributeGroupNode>modifiers:ModifiersNodetype:?TypeNodeampersand:?Tokenellipsis:?Tokenvariable:Expression\VariableNodeequals:?Tokendefault:?ExpressionNodeopenBrace:?Tokenhooks:?PlainNodeList<Member\PropertyHookNode>closeBrace:?Token$promoted: bool– Whether the parameter declares a property of the class, which its modifiers make it do.setType(?TypeNode $type): static– Writes the type before the variable with one space after it, or removes it with its space, its comments staying; a type standing in a tree comes as a copy without the trivia on its edges.getDocComment(): ?Trivia– Doc comment of the parameter: the one after it, before the separator or before the token after it where the last parameter has none, which PHP reads first, and else the one before it as for any node.
AttributeGroupNode
One #[...] group of attributes. Extends Node.
openBracket:Tokenitems:SeparatedNodeList<AttributeNode>closeBracket:Token
AttributeNode
Attribute with optional arguments. Extends Node.
name:NameNodearguments:?ArgumentListNode
ModifiersNode
Modifier keywords in source order (public, static, readonly, abstract,
final, var, public(set)…); may be empty. Extends Node. Implements
Countable, IteratorAggregate.
$visibility: Visibility– The visibility of the member,Publicwhere the modifiers write none;getVisibilityToken()tells whether one is written.$writeVisibility: Visibility– The visibility for writing as PHP takes it: the one asymmetric visibility declares apart (public(set)and its kin),Protectedfor a publicreadonly, which PHP writes asprotected(set), the$visibilityotherwise. It reads the modifiers alone, like$readonly, so a property of a readonly class is not taken for readonly.$static: bool$abstract: bool$final: bool$readonly: boolgetTokens(): list<Token>findToken(int $kind): ?Token– The modifier token of the kind, null when the modifiers do not have it.isEmpty(): boolhas(int $kind): boolgetVisibilityToken(): ?Token– Thepublic,protected,privateorvartoken, null when no visibility is written.append(Token $token): void– Appends a modifier. The first one opens the declaration, so it takes over the leading trivia of the token it now stands before, the open tag and the doc comment among them; one without trailing trivia is kept apart from what follows by a space.removeToken(Token $token): void– Removes a modifier. Its leading trivia go to the token after it, which may now open the declaration, and a comment after it stays: after the modifier before it, or on a line of its own above the token after it. A line the modifier ended after another token ends with that token now, which takes the line ending.count(): intgetIterator(): ArrayIterator<int, Token>– The modifier tokens, as a snapshot safe to iterate while mutating them.
PlainNodeList
Sequence of nodes without separators: statements, members, attribute groups. Extends NodeList. Implements
ArrayAccess, IteratorAggregate, Countable. The item type T is a subtype of
Node.
append(T $item): void– Appends an item, which takes the place in the lines of the list its neighbor has.insert(int $index, T $item): void– Inserts an item at the index. In a list standing in a file, an item that carries no trivia of its own takes the indentation of its neighbor and ends its line the same way.insertAfter(Node $item, Node $new): void– Inserts the new item right after the item, asinsert()does.insertBefore(Node $item, Node $new): void– Inserts the new item right before the item, asinsert()does.
SeparatedNodeList
Sequence of nodes with separator tokens between them and an optional trailing separator: parameters, arguments, array items,
imports. An item may be an empty node standing for nothing between two separators ([, $b] = $x). Extends
NodeList. Implements ArrayAccess, IteratorAggregate, Countable. The item type
T is a subtype of Node.
getSeparators(): list<Token>– The separators in source order, the trailing one included.hasTrailingSeparator(): bool– Whether a separator follows the last item.append(T $item, ?Token $separator = null): void– Appends an item; the separator before it is derived from the existing ones unless given.insert(int $index, T $item, ?Token $separator = null): void– Inserts an item at the index. A missing separator is modeled on the existing ones, or on `, ` in a one-line list, and then the item also takes the indentation and the line ending of its neighbor in a multi-line list; a separator given is inserted as it is. The separator is the one that goes with the item: the one after it, and for the last item the one before it, so what the separators already there carry stays with the items they follow.insertAfter(Node $item, Node $new, ?Token $separator = null): void– Inserts the new item right after the item, asinsert()does.insertBefore(Node $item, Node $new, ?Token $separator = null): void– Inserts the new item right before the item, asinsert()does.getTrailingSeparator(): ?Token– The separator after the last item; null where there is none.setTrailingSeparator(?Token $separator): static– Writes the separator after the last item, or removes it with null. The separator stands where the item ended: one without trivia of its own takes over the trailing trivia of the last item, or the trivia of the separator it replaces, and one removed leaves its comments and the end of its line to the last item; a separator with trivia keeps them, followed by the comments and the line ending of the one it replaces, and one in a list standing nowhere, as the parser builds it, is written as it is.removeItem(Node $item): void– Takes the item out with its trivia, together with the separator that goes with it, the one after it and for the last item the one before it, and tidies nothing;Node::remove()takes the lines with it.
FileNode
Root of the tree: the statements of a file and the end-of-file token carrying the trailing trivia. Extends
Node.
statements:PlainNodeList<StatementNode>endOfFile:Token$revision: int– Version of the tree: every write to a slot, a list, or the text or trivia of a token that changes it increments it.getTokens(): array– The tokens of the file in source order, kept by the index rather than collected anew.findNode(int $start, int $end, class-string<T> $class = 'PhpSyntax\\Node'): ?T– The outermost node of the class whose text stands exactly at the byte offsets of the current text, the end exclusive; the way a position of another tool (a parser of its own, an editor) is brought to the tree.
AnonymousClassNode
Anonymous class in a new expression: new class(...) extends A implements B { ... }. Extends
Node. Implements ClassLikeNode, AttributeAwareNode.
attributes:PlainNodeList<AttributeGroupNode>modifiers:ModifiersNodeclassKeyword:Tokenarguments:?ArgumentListNodeextendsKeyword:?Tokenextends:?NameNodeimplementsKeyword:?Tokenimplements:?SeparatedNodeList<NameNode>openBrace:Tokenmembers:PlainNodeList<MemberNode>closeBrace:Token
ArrayItemNode
Item of an array literal or a destructuring list: value with optional key, by reference or unpacked. Extends
Node.
key:?ExpressionNodedoubleArrow:?Tokenampersand:?Tokenellipsis:?Tokenvalue:ExpressionNode|DestructuringNode
SkippedArrayItemNode
Skipped item of a destructuring list ([, $b] = $x); has no tokens. Extends Node.
MatchArmNode
Arm of a match expression: the values compared with the subject, or default, and the result. Extends
Node.
values:?SeparatedNodeList<ExpressionNode>defaultKeyword:?Tokencomma:?TokendoubleArrow:Tokenresult:ExpressionNode
ClosureUseListNode
The use (...) clause of a closure. Extends Node.
useKeyword:TokenopenParen:Tokenitems:SeparatedNodeList<ClosureUseNode>closeParen:Token
ClosureUseNode
Variable captured by a closure, optionally by reference. Extends Node.
ampersand:?Tokenvariable:Expression\VariableNode
ElseifNode
elseif branch, in either syntax. Extends Node.
elseifKeyword:TokenopenParen:Tokencondition:ExpressionNodecloseParen:Tokenbody:?StatementNodecolon:?Tokenstatements:?PlainNodeList<StatementNode>
ElseNode
else branch, in either syntax; else if is an else with an if statement as
the body. Extends Node.
elseKeyword:Tokenbody:?StatementNodecolon:?Tokenstatements:?PlainNodeList<StatementNode>
CaseNode
case or default of a switch; the separator is a colon or a semicolon. Extends
Node.
keyword:Tokenvalue:?ExpressionNodeseparator:Tokenstatements:PlainNodeList<StatementNode>
CatchNode
catch clause with one or more types and an optional variable. Extends Node.
catchKeyword:TokenopenParen:Tokentypes:SeparatedNodeList<NameNode>variable:?Expression\VariableNodecloseParen:Tokenbody:Statement\BlockNode
FinallyNode
finally clause. Extends Node.
finallyKeyword:Tokenbody:Statement\BlockNode
DeclareItemNode
Directive of a declare statement: strict_types=1. Extends Node.
name:IdentifierNodeequals:Tokenvalue:ExpressionNode
StaticVariableNode
Variable of a static statement with an optional initializer. Extends Node.
variable:Expression\VariableNodeequals:?Tokendefault:?ExpressionNode
UseItemNode
Imported name with an optional alias; the type (function, const) appears only inside a group use.
What the item imports is said by the statement it stands in, the prefix of a group included, so an item is not moved from one
statement to another but written anew by UseNode::addImport(). Extends Node.
kindKeyword:?Tokenname:NameNodeasKeyword:?Tokenalias:?IdentifierNode$symbolKind: SymbolKind– What the item imports: its own type where a group use writes one per item, else what the statement imports.$fullName: string– The name the item imports, without a leading backslash: what is written here, and in a group use the prefix of the statement before it.remove(CommentPolicy $comments = CommentPolicy::MoveToNextToken, bool $mergeBlankLines = false): void– Removes the item asNode::remove()does, and the whole statement where the item is the only one it imports, whichStatementNode::remove()takes with its line.getStatement(): ?Statement\UseNode– The import the item belongs to; null for an item that is not in one.
ConstItemNode
Constant of a const statement or a class constant declaration. Extends Node.
name:IdentifierNodeequals:Tokenvalue:ExpressionNode
DestructuringNode
Destructuring, written list(...) or [...]; the keyword is null for the short form. A short array is
a literal until it stands where a place is assigned to, which is where it becomes one of these. It is no expression: it never
carries a value. Extends Node.
listKeyword:?TokenopenDelimiter:Tokenitems:SeparatedNodeList<ArrayItemNode|SkippedArrayItemNode>closeDelimiter:Token
Statements
Declarations and statements in PhpSyntax\Nodes\Statement: the items of the statements list of a file,
a block, a namespace, a case branch and the alternative syntax, and also the body of a control structure
(body).
NamespaceNode
namespace declaration; after namespace A; the following statements are nested in it. Extends
StatementNode.
namespaceKeyword:Tokenname:?NameNodesemicolon:?TokenopenBrace:?Tokenstatements:PlainNodeList<StatementNode>closeBrace:?Token
UseNode
use import of classes, functions or constants, written item by item or as a group under a prefix
(use A\{B, C};), which fills the slots the other form leaves empty. Extends StatementNode.
useKeyword:TokenkindKeyword:?Tokenprefix:?NameNodebackslash:?TokenopenBrace:?Tokenitems:SeparatedNodeList<UseItemNode>closeBrace:?Tokensemicolon:Token$symbolKind: SymbolKind– What the statement imports, which every item without a type of its own imports too.isGroup(): bool– Whether the items are written as a group under a prefix, which every one of them imports.addImport(string $name, ?string $alias = null, ?int $index = null): UseItemNode– Adds an import of the fully qualified name, written the way the statement writes its items: whole in a plain import, under the prefix in a group, which refuses a name standing outside it. The item imports what the statement imports and goes last unless an index says where.
ConstNode
const statement outside a class. Extends StatementNode. Implements
AttributeAwareNode.
attributes:PlainNodeList<AttributeGroupNode>constKeyword:Tokenitems:SeparatedNodeList<ConstItemNode>semicolon:Token
HaltCompilerNode
__halt_compiler(); the rest of the file is the data token. Extends StatementNode.
haltCompilerKeyword:TokenopenParen:TokencloseParen:Tokensemicolon:Tokendata:?Token
InlineHtmlNode
Text outside PHP tags, including a BOM or a hashbang line. Extends StatementNode.
html:TokenisPreamble(): bool– Whether the text is only what may precede the code of a pure PHP file: a byte order mark, a hashbang line, or both.
EmptyStatementNode
Bare semicolon, or a close tag after a terminated statement. Extends StatementNode.
semicolon:Token
ExpressionStatementNode
Expression as a statement. Extends StatementNode.
expression:ExpressionNodesemicolon:Token
BlockNode
Statements in braces. Extends StatementNode.
openBrace:Tokenstatements:PlainNodeList<StatementNode>closeBrace:TokeninterruptsFlow(): bool– Whether the code does not go on after the last statement of the block, the empty statement a close tag leaves behind it aside; false for an empty block.alwaysLeaves(): bool– Whether the code never goes on past the last statement of the block; false for an empty block.unwrap(): void– Moves the statements of the block into the list the block stands in, in its place, and removes the braces the wayremove()removes a node: a comment on the opening brace goes before the first statement, one on the closing brace after the last one, before what follows the block, both on lines of their own where the brace stood on one. The statements keep their trivia, the indentation included, whichIndentation::shift()moves a level up. ThrowsLogicExceptionfor a block whose braces stand next to a close tag or inline HTML, where the whitespace is output of the script, before anything moves.
IfNode
if statement in either syntax; the body is a statement, the alternative syntax fills statements. Extends
StatementNode.
ifKeyword:TokenopenParen:Tokencondition:ExpressionNodecloseParen:Tokenbody:?StatementNodecolon:?Tokenstatements:?PlainNodeList<StatementNode>elseifs:PlainNodeList<ElseifNode>else:?ElseNodeendKeyword:?Tokensemicolon:?TokenalwaysLeaves(): bool– Whether the code never goes on past theif: it has anelseand every branch leaves.
WhileNode
while loop in either syntax. Extends StatementNode.
whileKeyword:TokenopenParen:Tokencondition:ExpressionNodecloseParen:Tokenbody:?StatementNodecolon:?Tokenstatements:?PlainNodeList<StatementNode>endKeyword:?Tokensemicolon:?Token
DoWhileNode
do-while loop. Extends StatementNode.
doKeyword:Tokenbody:StatementNodewhileKeyword:TokenopenParen:Tokencondition:ExpressionNodecloseParen:Tokensemicolon:Token
ForNode
for loop in either syntax. Extends StatementNode.
forKeyword:TokenopenParen:Tokeninitializers:SeparatedNodeList<ExpressionNode>firstSemicolon:Tokenconditions:SeparatedNodeList<ExpressionNode>secondSemicolon:Tokenupdates:SeparatedNodeList<ExpressionNode>closeParen:Tokenbody:?StatementNodecolon:?Tokenstatements:?PlainNodeList<StatementNode>endKeyword:?Tokensemicolon:?Token
ForeachNode
foreach loop in either syntax. Extends StatementNode.
foreachKeyword:TokenopenParen:Tokenexpression:ExpressionNodeasKeyword:Tokenkey:?ExpressionNodedoubleArrow:?Tokenampersand:?Tokenvalue:ExpressionNode|DestructuringNodecloseParen:Tokenbody:?StatementNodecolon:?Tokenstatements:?PlainNodeList<StatementNode>endKeyword:?Tokensemicolon:?Token
SwitchNode
switch statement in either syntax; a semicolon may precede the first case. Extends
StatementNode.
switchKeyword:TokenopenParen:Tokensubject:ExpressionNodecloseParen:TokenopenBrace:?Tokencolon:?TokenleadingSemicolon:?Tokencases:PlainNodeList<CaseNode>closeBrace:?TokenendKeyword:?Tokensemicolon:?Token
BreakNode
break with an optional level. Extends StatementNode.
breakKeyword:Tokenlevel:?ExpressionNodesemicolon:Token
ContinueNode
continue with an optional level. Extends StatementNode.
continueKeyword:Tokenlevel:?ExpressionNodesemicolon:Token
ReturnNode
return with an optional value. Extends StatementNode.
returnKeyword:Tokenexpression:?ExpressionNodesemicolon:Token
GlobalNode
global statement. Extends StatementNode.
globalKeyword:Tokenvariables:SeparatedNodeList<Expression\VariableNode>semicolon:Token
StaticNode
static variable declaration. Extends StatementNode.
staticKeyword:Tokenvariables:SeparatedNodeList<StaticVariableNode>semicolon:Token
EchoNode
echo statement; the keyword may be the <?= open tag and the semicolon a close tag. Extends
StatementNode.
echoKeyword:Tokenexpressions:SeparatedNodeList<ExpressionNode>semicolon:Token
UnsetNode
unset statement. Extends StatementNode.
unsetKeyword:TokenopenParen:Tokenvariables:SeparatedNodeList<ExpressionNode>closeParen:Tokensemicolon:Token
DeclareNode
declare statement in its three forms: with a body, with a bare semicolon, or with the alternative syntax. Extends
StatementNode.
declareKeyword:TokenopenParen:Tokenitems:SeparatedNodeList<DeclareItemNode>closeParen:Tokenbody:?StatementNodecolon:?Tokenstatements:?PlainNodeList<StatementNode>endKeyword:?Tokensemicolon:?TokenfindDirective(string $name): ?DeclareItemNode– The directive of the name given, such asstrict_types, in any case as PHP reads it; null where none is.
TryNode
try statement with catches and an optional finally. Extends StatementNode.
tryKeyword:Tokenbody:Statement\BlockNodecatches:PlainNodeList<CatchNode>finally:?FinallyNodealwaysLeaves(): bool– Whether the code never goes on past thetry: itsfinallyleaves, or its body and everycatchdo.
GotoNode
goto statement. Extends StatementNode.
gotoKeyword:Tokenlabel:IdentifierNodesemicolon:Token
LabelNode
Label for goto. Extends StatementNode.
name:IdentifierNodecolon:Token
FunctionNode
Function declaration. Extends StatementNode. Implements FunctionLikeNode,
AttributeAwareNode.
attributes:PlainNodeList<AttributeGroupNode>functionKeyword:Tokenampersand:?Tokenname:IdentifierNodeopenParen:Tokenparameters:SeparatedNodeList<ParameterNode>closeParen:Tokencolon:?TokenreturnType:?TypeNodebody:Statement\BlockNodesetReturnType(?TypeNode $type): static– Writes the return type with its colon, or removes both, asFunctionLikeNode::setReturnType()says.
ClassNode
Class declaration. Extends StatementNode. Implements ClassLikeNode,
AttributeAwareNode.
attributes:PlainNodeList<AttributeGroupNode>modifiers:ModifiersNodeclassKeyword:Tokenname:IdentifierNodeextendsKeyword:?Tokenextends:?NameNodeimplementsKeyword:?Tokenimplements:?SeparatedNodeList<NameNode>openBrace:Tokenmembers:PlainNodeList<MemberNode>closeBrace:Token
InterfaceNode
Interface declaration. Extends StatementNode. Implements ClassLikeNode,
AttributeAwareNode.
attributes:PlainNodeList<AttributeGroupNode>interfaceKeyword:Tokenname:IdentifierNodeextendsKeyword:?Tokenextends:?SeparatedNodeList<NameNode>openBrace:Tokenmembers:PlainNodeList<MemberNode>closeBrace:Token
TraitNode
Trait declaration. Extends StatementNode. Implements ClassLikeNode,
AttributeAwareNode.
attributes:PlainNodeList<AttributeGroupNode>traitKeyword:Tokenname:IdentifierNodeopenBrace:Tokenmembers:PlainNodeList<MemberNode>closeBrace:Token
EnumNode
Enum declaration, optionally backed by a scalar type. Extends StatementNode. Implements
ClassLikeNode, AttributeAwareNode.
attributes:PlainNodeList<AttributeGroupNode>enumKeyword:Tokenname:IdentifierNodecolon:?TokenbackingType:?TypeNodeimplementsKeyword:?Tokenimplements:?SeparatedNodeList<NameNode>openBrace:Tokenmembers:PlainNodeList<MemberNode>closeBrace:Token
Expressions
Expressions in PhpSyntax\Nodes\Expression: operators, calls, accesses, assignments, closures and arrow functions.
Literals have their own section Scalars, destructuring is in the section Common Nodes.
VariableNode
Variable: $a, $$a, ${expr}; inside a string also a bare name in ${name}.
Extends ExpressionNode.
dollar:?TokenopenBrace:?Tokenname:Token|ExpressionNodecloseBrace:?Token$plainName: ?string– The name without the dollar sign; null where the name is an expression ($$a,${expr}).isThis(): bool– Whether the variable is$this, the object a method runs on.rename(string $name): static– Writes the name of the variable, without the dollar sign: a plain name changes its text, and a name given by an expression is replaced by a variable token, the dollar and the braces around the expression gone and the trivia on its edges kept, so that$plainNamereads the new name.
ArrayAccessNode
Array or string offset access: $a[$i], $a[]. Extends ExpressionNode.
expression:ExpressionNodeopenBracket:Tokenindex:?ExpressionNodecloseBracket:Token
PropertyFetchNode
Property access with -> or ?->; the name may be an identifier, a variable or a braced
expression. Extends ExpressionNode.
object:ExpressionNodeoperator:TokenopenBrace:?Tokenname:IdentifierNode|ExpressionNodecloseBrace:?Token$plainName: ?string– The name of the property; null where the name is a variable or an expression ($a->$b,$a->{expr}).$nullsafe: bool– Whether the fetch is written with?->, which skips it when the object is null.isOfThis(): bool– Whether the property is one of$this, with either operator.rename(string $name): static– Writes the name of the property, an identifier: a plain name changes its text, and a name given by an expression is replaced by the identifier, its braces gone and the trivia on its edges kept, so that$plainNamereads the new name.
StaticPropertyFetchNode
Static property access: A::$b, A::$$b, A::${expr}. The name is written the way a
variable is, dollar and braces included, but it names a property. Extends ExpressionNode.
class:NameNode|ExpressionNodedoubleColon:Tokendollar:?TokenopenBrace:?Tokenname:Token|ExpressionNodecloseBrace:?Token$plainName: ?string– The name of the property without the dollar sign; null where the name is an expression ($$b,${expr}).rename(string $name): static– Writes the name of the property, without the dollar sign: a plain name changes its text, and a name given by an expression is replaced by a variable token, the dollar and the braces around the expression gone and the trivia on its edges kept, so that$plainNamereads the new name.
ClassConstantFetchNode
Class constant access: A::B, A::class, A::{expr}. Extends
ExpressionNode.
class:NameNode|ExpressionNodedoubleColon:TokenopenBrace:?Tokenname:IdentifierNode|ExpressionNodecloseBrace:?Token$plainName: ?string– The name of the constant; null where the name is an expression (A::{expr}).rename(string $name): static– Writes the name of the constant, an identifier: a plain name changes its text, and a name given by an expression is replaced by the identifier, its braces gone and the trivia on its edges kept, so that$plainNamereads the new name.
ConstantFetchNode
Constant access by name: FOO, \Foo\BAR. Extends ExpressionNode.
name:NameNode
FunctionCallNode
Function call by name or on an expression. Extends ExpressionNode.
name:NameNode|ExpressionNodearguments:ArgumentListNode
MethodCallNode
Method call with -> or ?->. Extends ExpressionNode.
object:ExpressionNodeoperator:TokenopenBrace:?Tokenname:IdentifierNode|ExpressionNodecloseBrace:?Tokenarguments:ArgumentListNode$plainName: ?string– The name of the method; null where the name is a variable or an expression ($a->$b(),$a->{expr}()).$nullsafe: bool– Whether the call is written with?->, which skips it when the object is null.isOfThis(): bool– Whether the method is one of$this, with either operator.rename(string $name): static– Writes the name of the method, an identifier: a plain name changes its text, and a name given by an expression is replaced by the identifier, its braces gone and the trivia on its edges kept, so that$plainNamereads the new name.
StaticMethodCallNode
Static method call: A::b(), $a::b(), A::{expr}(). Extends
ExpressionNode.
class:NameNode|ExpressionNodedoubleColon:TokenopenBrace:?Tokenname:IdentifierNode|ExpressionNodecloseBrace:?Tokenarguments:ArgumentListNode$plainName: ?string– The name of the method; null where the name is an expression (A::{expr}()).rename(string $name): static– Writes the name of the method, an identifier: a plain name changes its text, and a name given by an expression is replaced by the identifier, its braces gone and the trivia on its edges kept, so that$plainNamereads the new name.
NewNode
Instantiation of a named, dynamic or anonymous class. Extends ExpressionNode. Implements
OperatorNode.
newKeyword:Tokenclass:NameNode|ExpressionNode|AnonymousClassNodearguments:?ArgumentListNode
ArrayNode
Array literal in either syntax: [...] or array(...). A short array standing where a place is
assigned to destructures instead, and is a DestructuringNode. Extends ExpressionNode.
arrayKeyword:?TokenopenDelimiter:Tokenitems:SeparatedNodeList<ArrayItemNode|SkippedArrayItemNode>closeDelimiter:Token
AssignmentNode
Assignment $a = $b. Extends ExpressionNode. Implements OperatorNode.
target:ExpressionNode|DestructuringNodeequals:Tokenexpression:ExpressionNode
CombinedAssignmentNode
Combined assignment $a += $b, whose operator token tells which operation is baked into it. Extends
ExpressionNode. Implements OperatorNode.
target:ExpressionNodeoperator:Tokenexpression:ExpressionNodereplaceOperator(string $operator): void– Replaces the operator by another combined assignment one, the trivia around it staying; every one binds alike, so no parentheses change. ThrowsInvalidArgumentExceptionfor what is no combined assignment operator.
AssignmentByReferenceNode
Assignment by reference $a = &$b; the grammar takes a variable or a new expression on the right.
Extends ExpressionNode. Implements OperatorNode.
target:ExpressionNodeequals:Tokenampersand:Tokenexpression:ExpressionNode
BinaryOpNode
Binary operation; the operator token tells which (arithmetic, comparison, logical, bitwise, concatenation, coalesce, pipe).
Extends ExpressionNode. Implements OperatorNode.
left:ExpressionNodeoperator:Tokenright:ExpressionNodereplaceOperator(string $operator): void– Replaces the operator by another binary one, the trivia around it staying, and puts the operands and the operation itself in parentheses where the new precedence asks, taking away those it makes needless. ThrowsInvalidArgumentExceptionfor what is no binary operator.isLogical(): bool– Whether the operator is&&,||,and,ororxor, the operators the parts of a condition are chained with.
UnaryOpNode
Unary operation written before its operand: +, -, !, ~, @;
++ and -- are a PrefixOpNode. Extends ExpressionNode. Implements
OperatorNode.
operator:Tokenexpression:ExpressionNodereplaceOperator(string $operator): void– Replaces the operator by another unary one, the trivia around it staying, and puts the operand and the operation itself in parentheses where the new precedence asks,!binding looser than the rest. ThrowsInvalidArgumentExceptionfor what is no unary operator.
PrefixOpNode
Prefix increment or decrement. Extends ExpressionNode. Implements OperatorNode.
operator:Tokentarget:ExpressionNode
PostfixOpNode
Postfix increment or decrement. Extends ExpressionNode. Implements OperatorNode.
target:ExpressionNodeoperator:Token
CastNode
Type cast; the cast token keeps its spelling including inner whitespace: ( int ). Extends ExpressionNode.
Implements OperatorNode.
operator:Tokenexpression:ExpressionNode$typeName: string– The type the cast converts to, in the name PHP knows it by: (integer) is int, (double) and (real) are float.replaceOperator(string $operator): void– Replaces the cast by another one,(int)by(string)for instance, the trivia around it staying; every cast binds alike, so no parentheses change. Another spelling of the same cast issetText()of the operator. ThrowsInvalidArgumentExceptionfor what is no cast.
TernaryNode
Ternary conditional $a ? $b : $c, or the elvis form $a ?: $c leaving then empty. Extends
ExpressionNode. Implements OperatorNode.
condition:ExpressionNodequestion:Tokenthen:?ExpressionNodecolon:Tokenelse:ExpressionNode
InstanceofNode
instanceof check against a name or a dynamic class. Extends ExpressionNode. Implements
OperatorNode.
expression:ExpressionNodeinstanceofKeyword:Tokenclass:NameNode|ExpressionNode
ParenthesizedNode
Expression in parentheses. Extends ExpressionNode.
openParen:Tokenexpression:ExpressionNodecloseParen:TokenisRedundant(): bool– Whether the parentheses may go without the code coming to mean anything else: what stands in them binds at least as tightly as the place they stand in asks, and what reaches into them could reach into it bare. Where the answer is not certain it is no.
IssetNode
isset(...) with one or more variables. Extends ExpressionNode.
issetKeyword:TokenopenParen:Tokenvariables:SeparatedNodeList<ExpressionNode>closeParen:Token
EmptyNode
empty(...). Extends ExpressionNode.
emptyKeyword:TokenopenParen:Tokenexpression:ExpressionNodecloseParen:Token
EvalNode
eval(...). Extends ExpressionNode.
evalKeyword:TokenopenParen:Tokenexpression:ExpressionNodecloseParen:Token
IncludeNode
include, include_once, require or require_once; the keyword token tells
which. Extends ExpressionNode. Implements RightExtendingNode, OperatorNode.
includeKeyword:Tokenexpression:ExpressionNode
ExitNode
exit or die with optional arguments. Extends ExpressionNode.
exitKeyword:Tokenarguments:?ArgumentListNode
PrintNode
print expression. Extends ExpressionNode. Implements RightExtendingNode,
OperatorNode.
printKeyword:Tokenexpression:ExpressionNode
YieldNode
yield, yield $value or yield $key => $value. Extends ExpressionNode.
Implements RightExtendingNode, OperatorNode.
yieldKeyword:Tokenkey:?ExpressionNodedoubleArrow:?Tokenvalue:?ExpressionNode
YieldFromNode
yield from expression. Extends ExpressionNode. Implements RightExtendingNode,
OperatorNode.
yieldFromKeyword:Tokenexpression:ExpressionNode
ThrowNode
throw expression. Extends ExpressionNode. Implements RightExtendingNode,
OperatorNode.
throwKeyword:Tokenexpression:ExpressionNode
CloneNode
clone expression; clone(...) with arguments is a function call. Extends ExpressionNode.
Implements OperatorNode.
cloneKeyword:Tokenexpression:ExpressionNode
MatchNode
match expression. Extends ExpressionNode.
matchKeyword:TokenopenParen:Tokensubject:ExpressionNodecloseParen:TokenopenBrace:Tokenarms:SeparatedNodeList<MatchArmNode>closeBrace:Token
ClosureNode
Anonymous function, optionally static, with captured variables. Extends ExpressionNode. Implements
AnonymousFunctionNode, AttributeAwareNode, FunctionLikeNode.
attributes:PlainNodeList<AttributeGroupNode>staticKeyword:?TokenfunctionKeyword:Tokenampersand:?TokenopenParen:Tokenparameters:SeparatedNodeList<ParameterNode>closeParen:Tokenuses:?ClosureUseListNodecolon:?TokenreturnType:?TypeNodebody:Statement\BlockNodesetReturnType(?TypeNode $type): static– Writes the return type with its colon, or removes both, asFunctionLikeNode::setReturnType()says.getCapturedVariableNames(): list<string>– Names of the variables the closure captures withuse (...), without the dollar sign.
ArrowFunctionNode
Arrow function fn(...) => expr, optionally static. Extends ExpressionNode. Implements
AnonymousFunctionNode, RightExtendingNode, AttributeAwareNode,
FunctionLikeNode, OperatorNode.
attributes:PlainNodeList<AttributeGroupNode>staticKeyword:?TokenfnKeyword:Tokenampersand:?TokenopenParen:Tokenparameters:SeparatedNodeList<ParameterNode>closeParen:Tokencolon:?TokenreturnType:?TypeNodedoubleArrow:Tokenexpression:ExpressionNodesetReturnType(?TypeNode $type): static– Writes the return type with its colon, or removes both, asFunctionLikeNode::setReturnType()says.
ShellExecNode
Command in backticks with interpolation. Extends ExpressionNode.
openBacktick:Tokenparts:PlainNodeList<Scalar\InterpolatedStringPartNode|Scalar\InterpolationNode|ExpressionNode>closeBacktick:Token
Class Members
Properties, constants, methods, enum cases, hooks and trait uses in PhpSyntax\Nodes\Member.
PropertyNode
Property declaration; one or more properties, optionally with hooks. Extends MemberNode. Implements
AttributeAwareNode.
attributes:PlainNodeList<AttributeGroupNode>modifiers:ModifiersNodetype:?TypeNodeitems:SeparatedNodeList<Member\PropertyItemNode>semicolon:?TokenopenBrace:?Tokenhooks:?PlainNodeList<Member\PropertyHookNode>closeBrace:?TokensetType(?TypeNode $type): static– Writes the type before the items with one space after it, or removes it with its space, its comments staying; a type standing in a tree comes as a copy without the trivia on its edges.
PropertyItemNode
One property of a declaration with an optional default. Extends Node.
name:Tokenequals:?Tokendefault:?ExpressionNode$plainName: string– The name of the property without the dollar sign.
PropertyHookNode
Property hook (get, set) with a block body, an arrow body or none. Extends Node. Implements
FunctionLikeNode, AttributeAwareNode.
attributes:PlainNodeList<AttributeGroupNode>modifiers:ModifiersNodeampersand:?Tokenname:IdentifierNodeopenParen:?Tokenparameters:?SeparatedNodeList<ParameterNode>closeParen:?Tokenbody:?Statement\BlockNodedoubleArrow:?Tokenexpression:?ExpressionNodesemicolon:?TokensetReturnType(?TypeNode $type): static– ThrowsLogicExceptionalways, a property hook has no return type.
ClassConstNode
Class constant declaration, optionally typed. Extends MemberNode. Implements AttributeAwareNode.
attributes:PlainNodeList<AttributeGroupNode>modifiers:ModifiersNodeconstKeyword:Tokentype:?TypeNodeitems:SeparatedNodeList<ConstItemNode>semicolon:TokenisOverridable(): bool– Whether a descendant may declare the constant again: it is neither private nor final, and its class may be extended.
MethodNode
Method declaration; abstract and interface methods end with a semicolon instead of a body. Extends MemberNode.
Implements FunctionLikeNode, AttributeAwareNode.
attributes:PlainNodeList<AttributeGroupNode>modifiers:ModifiersNodefunctionKeyword:Tokenampersand:?Tokenname:IdentifierNodeopenParen:Tokenparameters:SeparatedNodeList<ParameterNode>closeParen:Tokencolon:?TokenreturnType:?TypeNodebody:?Statement\BlockNodesemicolon:?TokensetReturnType(?TypeNode $type): static– Writes the return type with its colon, or removes both, asFunctionLikeNode::setReturnType()says.isConstructor(): bool– Whether the method is the constructor, whose name PHP compares without regard to letter case.isDestructor(): bool– Whether the method is the destructor, whose name PHP compares without regard to letter case.isOverridable(): bool– Whether a descendant may declare the method again: it is neither private nor final, and its class may be extended.
TraitUseNode
use of traits with optional adaptations in braces. Extends MemberNode.
useKeyword:Tokentraits:SeparatedNodeList<NameNode>semicolon:?TokenopenBrace:?Tokenadaptations:?PlainNodeList<Member\TraitAdaptationNode>closeBrace:?Token
TraitPrecedenceNode
Trait adaptation A::m insteadof B. Extends Member\TraitAdaptationNode.
trait:NameNodedoubleColon:Tokenmethod:IdentifierNodeinsteadofKeyword:Tokentraits:SeparatedNodeList<NameNode>semicolon:Token
TraitAliasNode
Trait adaptation m as [modifier] [alias]. Extends Member\TraitAdaptationNode.
trait:?NameNodedoubleColon:?Tokenmethod:IdentifierNodeasKeyword:Tokenmodifier:?Tokenalias:?IdentifierNodesemicolon:Token
EnumCaseNode
Enum case with an optional backing value. Extends MemberNode. Implements AttributeAwareNode.
attributes:PlainNodeList<AttributeGroupNode>caseKeyword:Tokenname:IdentifierNodeequals:?Tokenvalue:?ExpressionNodesemicolon:Token
Scalars
Numbers, strings and their interpolation, true, false, null and magic constants in
PhpSyntax\Nodes\Scalar; the text stays as it was written.
IntegerNode
Integer literal in any base, kept as written. Extends ScalarNode.
token:Token$base: int– The base the literal is written in: 2, 8, 10 or 16; a leading zero alone is the old octal notation.toValue(): int– The value of the literal; a literal beyond the integer range is a float to PHP, so it is a FloatNode.
FloatNode
Literal PHP reads as a float, kept as written. That is not the same as float syntax: an integer literal beyond the integer
range is a float to PHP whatever its base (0xFFFFFFFFFFFFFFFF as much as 9223372036854775808), and the
lexer hands it over as one, so such a literal is a node of this class. Extends ScalarNode.
token:TokentoValue(): float– The value of the literal, which is also how an integer literal beyond the integer range reaches PHP.
BooleanNode
Boolean literal, kept in the letter case and with the leading backslash it is written with: true,
FALSE, \True. Extends ScalarNode.
token:Token
NullNode
Null literal, kept in the letter case and with the leading backslash it is written with: null, NULL,
\Null. Extends ScalarNode.
token:Token
StringNode
String literal without interpolation, quotes included. Extends ScalarNode.
token:Token$quote: string– The delimiter the literal is written with:'or", aborBprefix left out.static fromValue(string $value, string $quote = "'"): Scalar\StringNode– A literal standing for the value, escaped as the delimiter needs it.toValue(): string– The value of the literal with its escape sequences resolved.setValue(string $value, ?string $quote = null): static– Writes the literal: the value escaped as the delimiter needs it, in the delimiter given or in the one it has. The two go together, because the delimiter decides how the value is written. A literal that already reads as the value, in that delimiter, stays as it is written.
UnquotedStringNode
Name of an offset written without quotes inside an interpolated string ("$row[label]"), which PHP reads as a
string; having no delimiter, it stands for itself and holds no escape sequence. Extends ScalarNode.
token:TokentoValue(): string– The value of the offset, which is the text as it stands.
MagicConstantNode
Magic constant: __LINE__, __FILE__, __DIR__, __CLASS__,
__TRAIT__, __METHOD__, __FUNCTION__, __PROPERTY__, __NAMESPACE__.
Extends ScalarNode.
token:Token
InterpolatedStringNode
Double-quoted string with interpolated variables or expressions. Extends ScalarNode.
openQuote:Tokenparts:PlainNodeList<Scalar\InterpolatedStringPartNode|Scalar\InterpolationNode|ExpressionNode>closeQuote:Token
HeredocNode
Heredoc or nowdoc; the closing delimiter keeps its indentation, the parts keep theirs. Extends ScalarNode.
openDelimiter:Tokenparts:PlainNodeList<Scalar\InterpolatedStringPartNode|Scalar\InterpolationNode|ExpressionNode>closeDelimiter:Token$label: string– The label between <<< and the body, without quotes.$indentation: string– The indentation of the closing delimiter, which the body shares.toValue(): string– The text of the body with its escape sequences resolved and the common indentation removed. ThrowsLogicExceptionwhen the heredoc interpolates;hasInterpolation()tells beforehand.isNowdoc(): bool– Whether the label is in single quotes, which makes a nowdoc that resolves no escape sequences.hasInterpolation(): bool– Whether any part of the body is an interpolation, which leaves the heredoc without a value of its own.
InterpolatedStringPartNode
Literal text between interpolations, whitespace included. What its escape sequences mean depends on the string it stands in, so
the part keeps them as written and whoever reads it resolves them for that string, as HeredocNode::toValue() does for
a heredoc. Extends Node.
token:Token
InterpolationNode
Braced interpolation inside a string: {$expr}, ${name}, ${name[expr]} or
${expr}. Extends Node.
openBrace:Tokenexpression:ExpressionNodecloseBrace:Token
Types
Type declarations of parameters, properties, class constants and return values, and the backing type of an enum
(enum Suit: string) in PhpSyntax\Nodes\Type.
NamedTypeNode
Type given by a name: builtin (int, static, array, callable) or a class.
Extends TypeNode.
name:NameNodeisBuiltin(): bool– Whether the type is one PHP knows itself,self,staticandparentamong them.
NullableTypeNode
Nullable type: ?T. Extends TypeNode.
question:Tokentype:Type\NamedTypeNode
UnionTypeNode
Union type A|B; a member may be a parenthesized intersection (DNF). Extends TypeNode.
types:SeparatedNodeList<Type\NamedTypeNode|Type\IntersectionTypeNode>
IntersectionTypeNode
Intersection type A&B, parenthesized inside a union. Extends TypeNode.
openParen:?Tokentypes:SeparatedNodeList<Type\NamedTypeNode>closeParen:?Token