Přehled uzlů

Referenční přehled všech tříd uzlů: popis, sloty i s typem a veřejné vlastnosti a metody. Slot je pojmenovaný podle role, ne podle textu (ifKeyword, openParen, body), párové oddělovače jsou vždy open* a close*, seznam uzlů má jméno v množném čísle (statements, members) a ? značí slot, který může být prázdný.

Třídy leží v PhpSyntax\Nodes a jeho podprostorech Statement, Expression, Member, Scalar a Type; jména v typech jsou psaná relativně k PhpSyntax\Nodes (Expression\VariableNode), třídy mimo něj relativně k PhpSyntax (Token). Slot typu Token drží jeden token, PlainNodeList<T> seznam uzlů bez oddělovačů a SeparatedNodeList<T> seznam s oddělovači mezi položkami, oba podtypy NodeList<T>: čárkami, svislítky ve sjednocení typů a v catch a ampersandy v průniku typů. U každé třídy jsou nejdřív sloty a pak konstanty, vlastnosti a metody, které třída sama přidává; co umí každý uzel, je u Node, co každý výraz, u ExpressionNode. Popisy jsou převzaté z dokumentačních komentářů v kódu, proto jsou anglicky. Jak strom číst a měnit, říkají stránky Uzly a sloty a Úpravy stromu.

Bázové třídy a rozhraní

Předci a rozhraní, podle kterých se uzly hledají a filtrují ($file->find(ExpressionNode::class)). Node leží v PhpSyntax, TraitAdaptationNode v PhpSyntax\Nodes\Member a ostatní v 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 and ModifiersNode answer with the collection their child is in, items, separators or tokens, which is read, not a slot to write.
  • getFile(): ?FileNode
  • getTokens(): 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: what matches() 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(): ?Token
  • getStartLine(): ?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 for getStartLine().
  • 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 for getStartLine().
  • 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 way Token::removeTrivia() does.
  • replaceDocComment(Trivia $docComment): void – Replaces the doc comment of the node (see getDocComment()) with the trivia given.
  • removeDocComment(): void – Removes the doc comment of the node (see getDocComment()) 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 one self, static and __CLASS__ name; null outside a class and in a function declared inside a method, which has no class scope. The arguments of new 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 way hasInnerComment() 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. A null leaves 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, . against 1 or return against FOO, 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; $text leaves 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. Rozšiřuje 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. Rozšiřuje 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. Rozšiřuje 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, new or clone, which has no place to write to. It says nothing about reading; that is isRepeatableRead(), 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, an ArrayAccess behind 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 of isRepeatableRead(), 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::C and X::class other than of static, 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->i before 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. Throws LogicException where the expression is written as no value; hasValue() tells beforehand.
  • hasValue(): bool – Whether the expression is written as a value, which is what toValue() gives.
  • replaceWithExpression(ExpressionNode $expression): void – Replaces this node by the expression the way replaceWith() does, in parentheses where the expression binds looser than the place asks or is reached into there: what ParenthesizedNode::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 that canStandInString(), 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. Throws InvalidArgumentException for an expression the place cannot hold, before anything moves, as checkReplaceWithExpression() tells beforehand.
  • checkReplaceWithExpression(ExpressionNode $expression): void – The dry run of replaceWithExpression(): 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}. Throws InvalidArgumentException for an expression the place cannot hold. Throws LogicException for 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. Rozšiřuje AttributeAwareNode.

  • $ampersand: ?Token – The & by which the declaration returns a reference, that of &get among 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. Throws LogicException for a property hook, which has no return type.

MemberNode

Member of a class-like declaration: property, constant, method, trait use, enum case. Rozšiřuje 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. Rozšiřuje Node. Implementuje Countable, IteratorAggregate, ArrayAccess. Typ položek T je podtyp Node.

  • getItems(): list<T>
  • isEmpty(): bool
  • append(T $item): void
  • insert(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, as insert() does.
  • insertBefore(Node $item, T $new): void – Inserts the new item right before the item, as insert() 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): int
  • count(): int
  • getIterator(): ArrayIterator<int, T> – The items, as a snapshot safe to iterate while mutating the list.
  • offsetExists(mixed $offset): bool
  • offsetGet(mixed $offset): T
  • offsetSet(mixed $offset, mixed $value): never
  • offsetUnset(mixed $offset): never
  • getFirstToken(): ?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. Rozšiřuje 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. Rozšiřuje ExpressionNode.

StatementNode

Statement: what a file, a block and the body of a control structure consist of. Rozšiřuje Node.

  • remove(CommentPolicy $comments = CommentPolicy::MoveToNextToken, bool $mergeBlankLines = false): void – Removes the statement as Node::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, throw or exit. It reads the statement itself, so an if whose 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 an if with an else, or every way through a try.

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. Rozšiřuje Node.

  • $method: IdentifierNode
  • $semicolon: Token

TypeNode

Type written in a declaration: a name, a nullable, a union or an intersection. Rozšiřuje Node.

  • isNullable(): bool – Whether the type accepts null: ?T, a union with null, and mixed.

Společné uzly

Kořen souboru, jména, seznamy, parametry, argumenty, atributy, části řídicích struktur a destrukturace; leží přímo v PhpSyntax\Nodes. DestructuringNode výrazem není, protože stojí jen tam, kam se přiřazuje, a hodnotu nemá.

NameNode

Name of a class, function, constant or namespace: one token of any kind, a keyword included (static, array, readonly). Rozšiřuje Node.

  • token: Token
  • $text: string – The name as it is written, the leading backslash and the namespace prefix 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 the namespace prefix.
  • $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 is isReference(): 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 as fromText() 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 is self, static or parent, 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 a use or a namespace statement introduces, not self, static or parent where 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, as readonly(...) calls a function of that name, and so does self() or the constant parent.
  • 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. Rozšiřuje Node.

  • token: Token
  • $text: string – The identifier as it is written; whether its letter case matters is up to what it names, which equals() 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 for class after ::; 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. Rozšiřuje Node.

  • openParen: Token
  • items: SeparatedNodeList<ArgumentNode|VariadicPlaceholderNode|ArgumentPlaceholderNode>
  • closeParen: Token
  • isPartialApplication(): 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 that get_class(object: $o) reads as the call get_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. Rozšiřuje Node.

  • name: ?IdentifierNode
  • colon: ?Token
  • ampersand: ?Token
  • ellipsis: ?Token
  • value: ExpressionNode

VariadicPlaceholderNode

The ... placeholder of a first-class callable or a partial application: f(...), f($a, ...). Rozšiřuje Node.

  • ellipsis: Token

ArgumentPlaceholderNode

The ? placeholder of a partial function application, optionally named: f(?), f(name: ?). Rozšiřuje Node.

  • name: ?IdentifierNode
  • colon: ?Token
  • question: Token

ParameterNode

Parameter of a function, method, closure, arrow function or hook; with modifiers it promotes a property. Rozšiřuje Node. Implementuje AttributeAwareNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • modifiers: ModifiersNode
  • type: ?TypeNode
  • ampersand: ?Token
  • ellipsis: ?Token
  • variable: Expression\VariableNode
  • equals: ?Token
  • default: ?ExpressionNode
  • openBrace: ?Token
  • hooks: ?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. Rozšiřuje Node.

  • openBracket: Token
  • items: SeparatedNodeList<AttributeNode>
  • closeBracket: Token

AttributeNode

Attribute with optional arguments. Rozšiřuje Node.

  • name: NameNode
  • arguments: ?ArgumentListNode

ModifiersNode

Modifier keywords in source order (public, static, readonly, abstract, final, var, public(set)…); may be empty. Rozšiřuje Node. Implementuje Countable, IteratorAggregate.

  • $visibility: Visibility – The visibility of the member, Public where 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), Protected for a public readonly, which PHP writes as protected(set), the $visibility otherwise. 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: bool
  • getTokens(): list<Token>
  • findToken(int $kind): ?Token – The modifier token of the kind, null when the modifiers do not have it.
  • isEmpty(): bool
  • has(int $kind): bool
  • getVisibilityToken(): ?Token – The public, protected, private or var token, 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(): int
  • getIterator(): 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. Rozšiřuje NodeList. Implementuje ArrayAccess, IteratorAggregate, Countable. Typ položek T je podtyp 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, as insert() does.
  • insertBefore(Node $item, Node $new): void – Inserts the new item right before the item, as insert() 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). Rozšiřuje NodeList. Implementuje ArrayAccess, IteratorAggregate, Countable. Typ položek T je podtyp 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, as insert() does.
  • insertBefore(Node $item, Node $new, ?Token $separator = null): void – Inserts the new item right before the item, as insert() 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. Rozšiřuje 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 { ... }. Rozšiřuje Node. Implementuje ClassLikeNode, AttributeAwareNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • modifiers: ModifiersNode
  • classKeyword: Token
  • arguments: ?ArgumentListNode
  • extendsKeyword: ?Token
  • extends: ?NameNode
  • implementsKeyword: ?Token
  • implements: ?SeparatedNodeList<NameNode>
  • openBrace: Token
  • members: PlainNodeList<MemberNode>
  • closeBrace: Token

ArrayItemNode

Item of an array literal or a destructuring list: value with optional key, by reference or unpacked. Rozšiřuje Node.

  • key: ?ExpressionNode
  • doubleArrow: ?Token
  • ampersand: ?Token
  • ellipsis: ?Token
  • value: ExpressionNode|DestructuringNode

SkippedArrayItemNode

Skipped item of a destructuring list ([, $b] = $x); has no tokens. Rozšiřuje Node.

MatchArmNode

Arm of a match expression: the values compared with the subject, or default, and the result. Rozšiřuje Node.

  • values: ?SeparatedNodeList<ExpressionNode>
  • defaultKeyword: ?Token
  • comma: ?Token
  • doubleArrow: Token
  • result: ExpressionNode

ClosureUseListNode

The use (...) clause of a closure. Rozšiřuje Node.

  • useKeyword: Token
  • openParen: Token
  • items: SeparatedNodeList<ClosureUseNode>
  • closeParen: Token

ClosureUseNode

Variable captured by a closure, optionally by reference. Rozšiřuje Node.

  • ampersand: ?Token
  • variable: Expression\VariableNode

ElseifNode

elseif branch, in either syntax. Rozšiřuje Node.

  • elseifKeyword: Token
  • openParen: Token
  • condition: ExpressionNode
  • closeParen: Token
  • body: ?StatementNode
  • colon: ?Token
  • statements: ?PlainNodeList<StatementNode>

ElseNode

else branch, in either syntax; else if is an else with an if statement as the body. Rozšiřuje Node.

  • elseKeyword: Token
  • body: ?StatementNode
  • colon: ?Token
  • statements: ?PlainNodeList<StatementNode>

CaseNode

case or default of a switch; the separator is a colon or a semicolon. Rozšiřuje Node.

  • keyword: Token
  • value: ?ExpressionNode
  • separator: Token
  • statements: PlainNodeList<StatementNode>

CatchNode

catch clause with one or more types and an optional variable. Rozšiřuje Node.

  • catchKeyword: Token
  • openParen: Token
  • types: SeparatedNodeList<NameNode>
  • variable: ?Expression\VariableNode
  • closeParen: Token
  • body: Statement\BlockNode

FinallyNode

finally clause. Rozšiřuje Node.

  • finallyKeyword: Token
  • body: Statement\BlockNode

DeclareItemNode

Directive of a declare statement: strict_types=1. Rozšiřuje Node.

  • name: IdentifierNode
  • equals: Token
  • value: ExpressionNode

StaticVariableNode

Variable of a static statement with an optional initializer. Rozšiřuje Node.

  • variable: Expression\VariableNode
  • equals: ?Token
  • default: ?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(). Rozšiřuje Node.

  • kindKeyword: ?Token
  • name: NameNode
  • asKeyword: ?Token
  • alias: ?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 as Node::remove() does, and the whole statement where the item is the only one it imports, which StatementNode::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. Rozšiřuje Node.

  • name: IdentifierNode
  • equals: Token
  • value: 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. Rozšiřuje Node.

  • listKeyword: ?Token
  • openDelimiter: Token
  • items: SeparatedNodeList<ArrayItemNode|SkippedArrayItemNode>
  • closeDelimiter: Token

Příkazy

Deklarace a příkazy v PhpSyntax\Nodes\Statement: položky seznamu statements souboru, bloku, jmenného prostoru, větve case a alternativní syntaxe, a také tělo řídicí struktury (body).

NamespaceNode

namespace declaration; after namespace A; the following statements are nested in it. Rozšiřuje StatementNode.

  • namespaceKeyword: Token
  • name: ?NameNode
  • semicolon: ?Token
  • openBrace: ?Token
  • statements: 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. Rozšiřuje StatementNode.

  • useKeyword: Token
  • kindKeyword: ?Token
  • prefix: ?NameNode
  • backslash: ?Token
  • openBrace: ?Token
  • items: SeparatedNodeList<UseItemNode>
  • closeBrace: ?Token
  • semicolon: 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. Rozšiřuje StatementNode. Implementuje AttributeAwareNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • constKeyword: Token
  • items: SeparatedNodeList<ConstItemNode>
  • semicolon: Token

HaltCompilerNode

__halt_compiler(); the rest of the file is the data token. Rozšiřuje StatementNode.

  • haltCompilerKeyword: Token
  • openParen: Token
  • closeParen: Token
  • semicolon: Token
  • data: ?Token

InlineHtmlNode

Text outside PHP tags, including a BOM or a hashbang line. Rozšiřuje StatementNode.

  • html: Token
  • isPreamble(): 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. Rozšiřuje StatementNode.

  • semicolon: Token

ExpressionStatementNode

Expression as a statement. Rozšiřuje StatementNode.

  • expression: ExpressionNode
  • semicolon: Token

BlockNode

Statements in braces. Rozšiřuje StatementNode.

  • openBrace: Token
  • statements: PlainNodeList<StatementNode>
  • closeBrace: Token
  • interruptsFlow(): 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 way remove() 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, which Indentation::shift() moves a level up. Throws LogicException for 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. Rozšiřuje StatementNode.

  • ifKeyword: Token
  • openParen: Token
  • condition: ExpressionNode
  • closeParen: Token
  • body: ?StatementNode
  • colon: ?Token
  • statements: ?PlainNodeList<StatementNode>
  • elseifs: PlainNodeList<ElseifNode>
  • else: ?ElseNode
  • endKeyword: ?Token
  • semicolon: ?Token
  • alwaysLeaves(): bool – Whether the code never goes on past the if: it has an else and every branch leaves.

WhileNode

while loop in either syntax. Rozšiřuje StatementNode.

  • whileKeyword: Token
  • openParen: Token
  • condition: ExpressionNode
  • closeParen: Token
  • body: ?StatementNode
  • colon: ?Token
  • statements: ?PlainNodeList<StatementNode>
  • endKeyword: ?Token
  • semicolon: ?Token

DoWhileNode

do-while loop. Rozšiřuje StatementNode.

  • doKeyword: Token
  • body: StatementNode
  • whileKeyword: Token
  • openParen: Token
  • condition: ExpressionNode
  • closeParen: Token
  • semicolon: Token

ForNode

for loop in either syntax. Rozšiřuje StatementNode.

  • forKeyword: Token
  • openParen: Token
  • initializers: SeparatedNodeList<ExpressionNode>
  • firstSemicolon: Token
  • conditions: SeparatedNodeList<ExpressionNode>
  • secondSemicolon: Token
  • updates: SeparatedNodeList<ExpressionNode>
  • closeParen: Token
  • body: ?StatementNode
  • colon: ?Token
  • statements: ?PlainNodeList<StatementNode>
  • endKeyword: ?Token
  • semicolon: ?Token

ForeachNode

foreach loop in either syntax. Rozšiřuje StatementNode.

  • foreachKeyword: Token
  • openParen: Token
  • expression: ExpressionNode
  • asKeyword: Token
  • key: ?ExpressionNode
  • doubleArrow: ?Token
  • ampersand: ?Token
  • value: ExpressionNode|DestructuringNode
  • closeParen: Token
  • body: ?StatementNode
  • colon: ?Token
  • statements: ?PlainNodeList<StatementNode>
  • endKeyword: ?Token
  • semicolon: ?Token

SwitchNode

switch statement in either syntax; a semicolon may precede the first case. Rozšiřuje StatementNode.

  • switchKeyword: Token
  • openParen: Token
  • subject: ExpressionNode
  • closeParen: Token
  • openBrace: ?Token
  • colon: ?Token
  • leadingSemicolon: ?Token
  • cases: PlainNodeList<CaseNode>
  • closeBrace: ?Token
  • endKeyword: ?Token
  • semicolon: ?Token

BreakNode

break with an optional level. Rozšiřuje StatementNode.

  • breakKeyword: Token
  • level: ?ExpressionNode
  • semicolon: Token

ContinueNode

continue with an optional level. Rozšiřuje StatementNode.

  • continueKeyword: Token
  • level: ?ExpressionNode
  • semicolon: Token

ReturnNode

return with an optional value. Rozšiřuje StatementNode.

  • returnKeyword: Token
  • expression: ?ExpressionNode
  • semicolon: Token

GlobalNode

global statement. Rozšiřuje StatementNode.

  • globalKeyword: Token
  • variables: SeparatedNodeList<Expression\VariableNode>
  • semicolon: Token

StaticNode

static variable declaration. Rozšiřuje StatementNode.

  • staticKeyword: Token
  • variables: SeparatedNodeList<StaticVariableNode>
  • semicolon: Token

EchoNode

echo statement; the keyword may be the <?= open tag and the semicolon a close tag. Rozšiřuje StatementNode.

  • echoKeyword: Token
  • expressions: SeparatedNodeList<ExpressionNode>
  • semicolon: Token

UnsetNode

unset statement. Rozšiřuje StatementNode.

  • unsetKeyword: Token
  • openParen: Token
  • variables: SeparatedNodeList<ExpressionNode>
  • closeParen: Token
  • semicolon: Token

DeclareNode

declare statement in its three forms: with a body, with a bare semicolon, or with the alternative syntax. Rozšiřuje StatementNode.

  • declareKeyword: Token
  • openParen: Token
  • items: SeparatedNodeList<DeclareItemNode>
  • closeParen: Token
  • body: ?StatementNode
  • colon: ?Token
  • statements: ?PlainNodeList<StatementNode>
  • endKeyword: ?Token
  • semicolon: ?Token
  • findDirective(string $name): ?DeclareItemNode – The directive of the name given, such as strict_types, in any case as PHP reads it; null where none is.

TryNode

try statement with catches and an optional finally. Rozšiřuje StatementNode.

  • tryKeyword: Token
  • body: Statement\BlockNode
  • catches: PlainNodeList<CatchNode>
  • finally: ?FinallyNode
  • alwaysLeaves(): bool – Whether the code never goes on past the try: its finally leaves, or its body and every catch do.

GotoNode

goto statement. Rozšiřuje StatementNode.

  • gotoKeyword: Token
  • label: IdentifierNode
  • semicolon: Token

LabelNode

Label for goto. Rozšiřuje StatementNode.

  • name: IdentifierNode
  • colon: Token

FunctionNode

Function declaration. Rozšiřuje StatementNode. Implementuje FunctionLikeNode, AttributeAwareNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • functionKeyword: Token
  • ampersand: ?Token
  • name: IdentifierNode
  • openParen: Token
  • parameters: SeparatedNodeList<ParameterNode>
  • closeParen: Token
  • colon: ?Token
  • returnType: ?TypeNode
  • body: Statement\BlockNode
  • setReturnType(?TypeNode $type): static – Writes the return type with its colon, or removes both, as FunctionLikeNode::setReturnType() says.

ClassNode

Class declaration. Rozšiřuje StatementNode. Implementuje ClassLikeNode, AttributeAwareNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • modifiers: ModifiersNode
  • classKeyword: Token
  • name: IdentifierNode
  • extendsKeyword: ?Token
  • extends: ?NameNode
  • implementsKeyword: ?Token
  • implements: ?SeparatedNodeList<NameNode>
  • openBrace: Token
  • members: PlainNodeList<MemberNode>
  • closeBrace: Token

InterfaceNode

Interface declaration. Rozšiřuje StatementNode. Implementuje ClassLikeNode, AttributeAwareNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • interfaceKeyword: Token
  • name: IdentifierNode
  • extendsKeyword: ?Token
  • extends: ?SeparatedNodeList<NameNode>
  • openBrace: Token
  • members: PlainNodeList<MemberNode>
  • closeBrace: Token

TraitNode

Trait declaration. Rozšiřuje StatementNode. Implementuje ClassLikeNode, AttributeAwareNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • traitKeyword: Token
  • name: IdentifierNode
  • openBrace: Token
  • members: PlainNodeList<MemberNode>
  • closeBrace: Token

EnumNode

Enum declaration, optionally backed by a scalar type. Rozšiřuje StatementNode. Implementuje ClassLikeNode, AttributeAwareNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • enumKeyword: Token
  • name: IdentifierNode
  • colon: ?Token
  • backingType: ?TypeNode
  • implementsKeyword: ?Token
  • implements: ?SeparatedNodeList<NameNode>
  • openBrace: Token
  • members: PlainNodeList<MemberNode>
  • closeBrace: Token

Výrazy

Výrazy v PhpSyntax\Nodes\Expression: operátory, volání, přístupy, přiřazení, closure a arrow funkce. Literály mají vlastní sekci Skaláry, destrukturace sekci Společné uzly.

VariableNode

Variable: $a, $$a, ${expr}; inside a string also a bare name in ${name}. Rozšiřuje ExpressionNode.

  • dollar: ?Token
  • openBrace: ?Token
  • name: Token|ExpressionNode
  • closeBrace: ?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 $plainName reads the new name.

ArrayAccessNode

Array or string offset access: $a[$i], $a[]. Rozšiřuje ExpressionNode.

  • expression: ExpressionNode
  • openBracket: Token
  • index: ?ExpressionNode
  • closeBracket: Token

PropertyFetchNode

Property access with -> or ?->; the name may be an identifier, a variable or a braced expression. Rozšiřuje ExpressionNode.

  • object: ExpressionNode
  • operator: Token
  • openBrace: ?Token
  • name: IdentifierNode|ExpressionNode
  • closeBrace: ?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 $plainName reads 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. Rozšiřuje ExpressionNode.

  • class: NameNode|ExpressionNode
  • doubleColon: Token
  • dollar: ?Token
  • openBrace: ?Token
  • name: Token|ExpressionNode
  • closeBrace: ?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 $plainName reads the new name.

ClassConstantFetchNode

Class constant access: A::B, A::class, A::{expr}. Rozšiřuje ExpressionNode.

  • class: NameNode|ExpressionNode
  • doubleColon: Token
  • openBrace: ?Token
  • name: IdentifierNode|ExpressionNode
  • closeBrace: ?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 $plainName reads the new name.

ConstantFetchNode

Constant access by name: FOO, \Foo\BAR. Rozšiřuje ExpressionNode.

  • name: NameNode

FunctionCallNode

Function call by name or on an expression. Rozšiřuje ExpressionNode.

  • name: NameNode|ExpressionNode
  • arguments: ArgumentListNode

MethodCallNode

Method call with -> or ?->. Rozšiřuje ExpressionNode.

  • object: ExpressionNode
  • operator: Token
  • openBrace: ?Token
  • name: IdentifierNode|ExpressionNode
  • closeBrace: ?Token
  • arguments: 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 $plainName reads the new name.

StaticMethodCallNode

Static method call: A::b(), $a::b(), A::{expr}(). Rozšiřuje ExpressionNode.

  • class: NameNode|ExpressionNode
  • doubleColon: Token
  • openBrace: ?Token
  • name: IdentifierNode|ExpressionNode
  • closeBrace: ?Token
  • arguments: 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 $plainName reads the new name.

NewNode

Instantiation of a named, dynamic or anonymous class. Rozšiřuje ExpressionNode. Implementuje OperatorNode.

  • newKeyword: Token
  • class: NameNode|ExpressionNode|AnonymousClassNode
  • arguments: ?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. Rozšiřuje ExpressionNode.

  • arrayKeyword: ?Token
  • openDelimiter: Token
  • items: SeparatedNodeList<ArrayItemNode|SkippedArrayItemNode>
  • closeDelimiter: Token

AssignmentNode

Assignment $a = $b. Rozšiřuje ExpressionNode. Implementuje OperatorNode.

  • target: ExpressionNode|DestructuringNode
  • equals: Token
  • expression: ExpressionNode

CombinedAssignmentNode

Combined assignment $a += $b, whose operator token tells which operation is baked into it. Rozšiřuje ExpressionNode. Implementuje OperatorNode.

  • target: ExpressionNode
  • operator: Token
  • expression: ExpressionNode
  • replaceOperator(string $operator): void – Replaces the operator by another combined assignment one, the trivia around it staying; every one binds alike, so no parentheses change. Throws InvalidArgumentException for what is no combined assignment operator.

AssignmentByReferenceNode

Assignment by reference $a = &$b; the grammar takes a variable or a new expression on the right. Rozšiřuje ExpressionNode. Implementuje OperatorNode.

  • target: ExpressionNode
  • equals: Token
  • ampersand: Token
  • expression: ExpressionNode

BinaryOpNode

Binary operation; the operator token tells which (arithmetic, comparison, logical, bitwise, concatenation, coalesce, pipe). Rozšiřuje ExpressionNode. Implementuje OperatorNode.

  • left: ExpressionNode
  • operator: Token
  • right: ExpressionNode
  • replaceOperator(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. Throws InvalidArgumentException for what is no binary operator.
  • isLogical(): bool – Whether the operator is &&, ||, and, or or xor, the operators the parts of a condition are chained with.

UnaryOpNode

Unary operation written before its operand: +, -, !, ~, @; ++ and -- are a PrefixOpNode. Rozšiřuje ExpressionNode. Implementuje OperatorNode.

  • operator: Token
  • expression: ExpressionNode
  • replaceOperator(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. Throws InvalidArgumentException for what is no unary operator.

PrefixOpNode

Prefix increment or decrement. Rozšiřuje ExpressionNode. Implementuje OperatorNode.

  • operator: Token
  • target: ExpressionNode

PostfixOpNode

Postfix increment or decrement. Rozšiřuje ExpressionNode. Implementuje OperatorNode.

  • target: ExpressionNode
  • operator: Token

CastNode

Type cast; the cast token keeps its spelling including inner whitespace: ( int ). Rozšiřuje ExpressionNode. Implementuje OperatorNode.

  • operator: Token
  • expression: 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 is setText() of the operator. Throws InvalidArgumentException for what is no cast.

TernaryNode

Ternary conditional $a ? $b : $c, or the elvis form $a ?: $c leaving then empty. Rozšiřuje ExpressionNode. Implementuje OperatorNode.

  • condition: ExpressionNode
  • question: Token
  • then: ?ExpressionNode
  • colon: Token
  • else: ExpressionNode

InstanceofNode

instanceof check against a name or a dynamic class. Rozšiřuje ExpressionNode. Implementuje OperatorNode.

  • expression: ExpressionNode
  • instanceofKeyword: Token
  • class: NameNode|ExpressionNode

ParenthesizedNode

Expression in parentheses. Rozšiřuje ExpressionNode.

  • openParen: Token
  • expression: ExpressionNode
  • closeParen: Token
  • isRedundant(): 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. Rozšiřuje ExpressionNode.

  • issetKeyword: Token
  • openParen: Token
  • variables: SeparatedNodeList<ExpressionNode>
  • closeParen: Token

EmptyNode

empty(...). Rozšiřuje ExpressionNode.

  • emptyKeyword: Token
  • openParen: Token
  • expression: ExpressionNode
  • closeParen: Token

EvalNode

eval(...). Rozšiřuje ExpressionNode.

  • evalKeyword: Token
  • openParen: Token
  • expression: ExpressionNode
  • closeParen: Token

IncludeNode

include, include_once, require or require_once; the keyword token tells which. Rozšiřuje ExpressionNode. Implementuje RightExtendingNode, OperatorNode.

  • includeKeyword: Token
  • expression: ExpressionNode

ExitNode

exit or die with optional arguments. Rozšiřuje ExpressionNode.

  • exitKeyword: Token
  • arguments: ?ArgumentListNode

PrintNode

print expression. Rozšiřuje ExpressionNode. Implementuje RightExtendingNode, OperatorNode.

  • printKeyword: Token
  • expression: ExpressionNode

YieldNode

yield, yield $value or yield $key => $value. Rozšiřuje ExpressionNode. Implementuje RightExtendingNode, OperatorNode.

  • yieldKeyword: Token
  • key: ?ExpressionNode
  • doubleArrow: ?Token
  • value: ?ExpressionNode

YieldFromNode

yield from expression. Rozšiřuje ExpressionNode. Implementuje RightExtendingNode, OperatorNode.

  • yieldFromKeyword: Token
  • expression: ExpressionNode

ThrowNode

throw expression. Rozšiřuje ExpressionNode. Implementuje RightExtendingNode, OperatorNode.

  • throwKeyword: Token
  • expression: ExpressionNode

CloneNode

clone expression; clone(...) with arguments is a function call. Rozšiřuje ExpressionNode. Implementuje OperatorNode.

  • cloneKeyword: Token
  • expression: ExpressionNode

MatchNode

match expression. Rozšiřuje ExpressionNode.

  • matchKeyword: Token
  • openParen: Token
  • subject: ExpressionNode
  • closeParen: Token
  • openBrace: Token
  • arms: SeparatedNodeList<MatchArmNode>
  • closeBrace: Token

ClosureNode

Anonymous function, optionally static, with captured variables. Rozšiřuje ExpressionNode. Implementuje AnonymousFunctionNode, AttributeAwareNode, FunctionLikeNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • staticKeyword: ?Token
  • functionKeyword: Token
  • ampersand: ?Token
  • openParen: Token
  • parameters: SeparatedNodeList<ParameterNode>
  • closeParen: Token
  • uses: ?ClosureUseListNode
  • colon: ?Token
  • returnType: ?TypeNode
  • body: Statement\BlockNode
  • setReturnType(?TypeNode $type): static – Writes the return type with its colon, or removes both, as FunctionLikeNode::setReturnType() says.
  • getCapturedVariableNames(): list<string> – Names of the variables the closure captures with use (...), without the dollar sign.

ArrowFunctionNode

Arrow function fn(...) => expr, optionally static. Rozšiřuje ExpressionNode. Implementuje AnonymousFunctionNode, RightExtendingNode, AttributeAwareNode, FunctionLikeNode, OperatorNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • staticKeyword: ?Token
  • fnKeyword: Token
  • ampersand: ?Token
  • openParen: Token
  • parameters: SeparatedNodeList<ParameterNode>
  • closeParen: Token
  • colon: ?Token
  • returnType: ?TypeNode
  • doubleArrow: Token
  • expression: ExpressionNode
  • setReturnType(?TypeNode $type): static – Writes the return type with its colon, or removes both, as FunctionLikeNode::setReturnType() says.

ShellExecNode

Command in backticks with interpolation. Rozšiřuje ExpressionNode.

  • openBacktick: Token
  • parts: PlainNodeList<Scalar\InterpolatedStringPartNode|Scalar\InterpolationNode|ExpressionNode>
  • closeBacktick: Token

Členy tříd

Vlastnosti, konstanty, metody, případy výčtu, hooky a použití traitů v PhpSyntax\Nodes\Member.

PropertyNode

Property declaration; one or more properties, optionally with hooks. Rozšiřuje MemberNode. Implementuje AttributeAwareNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • modifiers: ModifiersNode
  • type: ?TypeNode
  • items: SeparatedNodeList<Member\PropertyItemNode>
  • semicolon: ?Token
  • openBrace: ?Token
  • hooks: ?PlainNodeList<Member\PropertyHookNode>
  • closeBrace: ?Token
  • setType(?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. Rozšiřuje Node.

  • name: Token
  • equals: ?Token
  • default: ?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. Rozšiřuje Node. Implementuje FunctionLikeNode, AttributeAwareNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • modifiers: ModifiersNode
  • ampersand: ?Token
  • name: IdentifierNode
  • openParen: ?Token
  • parameters: ?SeparatedNodeList<ParameterNode>
  • closeParen: ?Token
  • body: ?Statement\BlockNode
  • doubleArrow: ?Token
  • expression: ?ExpressionNode
  • semicolon: ?Token
  • setReturnType(?TypeNode $type): static – Throws LogicException always, a property hook has no return type.

ClassConstNode

Class constant declaration, optionally typed. Rozšiřuje MemberNode. Implementuje AttributeAwareNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • modifiers: ModifiersNode
  • constKeyword: Token
  • type: ?TypeNode
  • items: SeparatedNodeList<ConstItemNode>
  • semicolon: Token
  • isOverridable(): 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. Rozšiřuje MemberNode. Implementuje FunctionLikeNode, AttributeAwareNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • modifiers: ModifiersNode
  • functionKeyword: Token
  • ampersand: ?Token
  • name: IdentifierNode
  • openParen: Token
  • parameters: SeparatedNodeList<ParameterNode>
  • closeParen: Token
  • colon: ?Token
  • returnType: ?TypeNode
  • body: ?Statement\BlockNode
  • semicolon: ?Token
  • setReturnType(?TypeNode $type): static – Writes the return type with its colon, or removes both, as FunctionLikeNode::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. Rozšiřuje MemberNode.

  • useKeyword: Token
  • traits: SeparatedNodeList<NameNode>
  • semicolon: ?Token
  • openBrace: ?Token
  • adaptations: ?PlainNodeList<Member\TraitAdaptationNode>
  • closeBrace: ?Token

TraitPrecedenceNode

Trait adaptation A::m insteadof B. Rozšiřuje Member\TraitAdaptationNode.

  • trait: NameNode
  • doubleColon: Token
  • method: IdentifierNode
  • insteadofKeyword: Token
  • traits: SeparatedNodeList<NameNode>
  • semicolon: Token

TraitAliasNode

Trait adaptation m as [modifier] [alias]. Rozšiřuje Member\TraitAdaptationNode.

  • trait: ?NameNode
  • doubleColon: ?Token
  • method: IdentifierNode
  • asKeyword: Token
  • modifier: ?Token
  • alias: ?IdentifierNode
  • semicolon: Token

EnumCaseNode

Enum case with an optional backing value. Rozšiřuje MemberNode. Implementuje AttributeAwareNode.

  • attributes: PlainNodeList<AttributeGroupNode>
  • caseKeyword: Token
  • name: IdentifierNode
  • equals: ?Token
  • value: ?ExpressionNode
  • semicolon: Token

Skaláry

Čísla, řetězce a jejich interpolace, true, false, null a magické konstanty v PhpSyntax\Nodes\Scalar; text zůstává tak, jak byl zapsán.

IntegerNode

Integer literal in any base, kept as written. Rozšiřuje 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. Rozšiřuje ScalarNode.

  • token: Token
  • toValue(): 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. Rozšiřuje ScalarNode.

  • token: Token

NullNode

Null literal, kept in the letter case and with the leading backslash it is written with: null, NULL, \Null. Rozšiřuje ScalarNode.

  • token: Token

StringNode

String literal without interpolation, quotes included. Rozšiřuje ScalarNode.

  • token: Token
  • $quote: string – The delimiter the literal is written with: ' or ", a b or B prefix 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. Rozšiřuje ScalarNode.

  • token: Token
  • toValue(): 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__. Rozšiřuje ScalarNode.

  • token: Token

InterpolatedStringNode

Double-quoted string with interpolated variables or expressions. Rozšiřuje ScalarNode.

  • openQuote: Token
  • parts: PlainNodeList<Scalar\InterpolatedStringPartNode|Scalar\InterpolationNode|ExpressionNode>
  • closeQuote: Token

HeredocNode

Heredoc or nowdoc; the closing delimiter keeps its indentation, the parts keep theirs. Rozšiřuje ScalarNode.

  • openDelimiter: Token
  • parts: 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. Throws LogicException when 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. Rozšiřuje Node.

  • token: Token

InterpolationNode

Braced interpolation inside a string: {$expr}, ${name}, ${name[expr]} or ${expr}. Rozšiřuje Node.

  • openBrace: Token
  • expression: ExpressionNode
  • closeBrace: Token

Typy

Typové deklarace parametrů, vlastností, konstant třídy a návratových hodnot a typ hodnot výčtu (enum Suit: string) v PhpSyntax\Nodes\Type.

NamedTypeNode

Type given by a name: builtin (int, static, array, callable) or a class. Rozšiřuje TypeNode.

  • name: NameNode
  • isBuiltin(): bool – Whether the type is one PHP knows itself, self, static and parent among them.

NullableTypeNode

Nullable type: ?T. Rozšiřuje TypeNode.

  • question: Token
  • type: Type\NamedTypeNode

UnionTypeNode

Union type A|B; a member may be a parenthesized intersection (DNF). Rozšiřuje TypeNode.

  • types: SeparatedNodeList<Type\NamedTypeNode|Type\IntersectionTypeNode>

IntersectionTypeNode

Intersection type A&B, parenthesized inside a union. Rozšiřuje TypeNode.

  • openParen: ?Token
  • types: SeparatedNodeList<Type\NamedTypeNode>
  • closeParen: ?Token