https://github.com/rectorphp/php-parser-nodes-docs
Visual documentation of PHP Parser nodes, to help you learn AST, how to create nodes and analyse them
https://github.com/rectorphp/php-parser-nodes-docs
php php-parser phpstan rector
Last synced: 4 months ago
JSON representation
Visual documentation of PHP Parser nodes, to help you learn AST, how to create nodes and analyse them
- Host: GitHub
- URL: https://github.com/rectorphp/php-parser-nodes-docs
- Owner: rectorphp
- Created: 2021-02-07T22:22:26.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-10-28T13:15:49.000Z (about 2 years ago)
- Last Synced: 2025-06-26T20:41:11.584Z (6 months ago)
- Topics: php, php-parser, phpstan, rector
- Language: PHP
- Homepage:
- Size: 54.7 KB
- Stars: 37
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node Overview
Here you can find overview of commonly used nodes and how to build PHP code from them. For all nodes, [check php-parser code](https://github.com/nikic/PHP-Parser/tree/master/lib/PhpParser/Node).
## `PhpParser\Node\Const_`
### Example PHP Code
```php
### Public Properties
* `$name` - `/** @var Identifier Name */`
* `$value` - `/** @var Expr Value */`
* `$namespacedName` - `/** @var Name|null Namespaced name (if using NameResolver) */`
## `PhpParser\Node\Expr\ArrayDimFetch`
### Example PHP Code
```php
### Public Properties
* `$var` - `/** @var Expr Variable */`
* `$dim` - `/** @var null|Expr Array index / dim */`
## `PhpParser\Node\Expr\ArrayItem`
### Example PHP Code
```php
$Tom
```
### Public Properties
* `$key` - `/** @var null|Expr Key */`
* `$value` - `/** @var Expr Value */`
* `$byRef` - `/** @var bool Whether to assign by reference */`
* `$unpack` - `/** @var bool Whether to unpack the argument */`
## `PhpParser\Node\Expr\Array_`
### Example PHP Code
```php
$Tom)
```
### Public Properties
* `$items` - `/** @var (ArrayItem|null)[] Items */`
## `PhpParser\Node\Expr\ArrowFunction`
### Example PHP Code
```php
1
```
### Public Properties
* `$static` - `/** @var bool */`
* `$byRef` - `/** @var bool */`
* `$params` - `/** @var Node\Param[] */`
* `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\ComplexType */`
* `$expr` - `/** @var Expr */`
* `$attrGroups` - `/** @var Node\AttributeGroup[] */`
## `PhpParser\Node\Expr\Assign`
### Example PHP Code
```php
```php
someProperty = 'some value'
```
### Public Properties
* `$var` - `/** @var Expr Variable */`
* `$expr` - `/** @var Expr Expression */`
## `PhpParser\Node\Expr\AssignOp\Coalesce`
### Example PHP Code
```php
### Public Properties
* `$var` - `/** @var Expr Variable */`
* `$expr` - `/** @var Expr Expression */`
## `PhpParser\Node\Expr\AssignOp\Concat`
### Example PHP Code
```php
### Public Properties
* `$var` - `/** @var Expr Variable */`
* `$expr` - `/** @var Expr Expression */`
## `PhpParser\Node\Expr\BinaryOp\BooleanAnd`
### Example PHP Code
```php
### Public Properties
* `$left` - `/** @var Expr The left hand side expression */`
* `$right` - `/** @var Expr The right hand side expression */`
## `PhpParser\Node\Expr\BinaryOp\Coalesce`
### Example PHP Code
```php
### Public Properties
* `$left` - `/** @var Expr The left hand side expression */`
* `$right` - `/** @var Expr The right hand side expression */`
## `PhpParser\Node\Expr\BinaryOp\Concat`
### Example PHP Code
```php
### Public Properties
* `$left` - `/** @var Expr The left hand side expression */`
* `$right` - `/** @var Expr The right hand side expression */`
## `PhpParser\Node\Expr\BinaryOp\Equal`
### Example PHP Code
```php
### Public Properties
* `$left` - `/** @var Expr The left hand side expression */`
* `$right` - `/** @var Expr The right hand side expression */`
## `PhpParser\Node\Expr\BinaryOp\Identical`
### Example PHP Code
```php
### Public Properties
* `$left` - `/** @var Expr The left hand side expression */`
* `$right` - `/** @var Expr The right hand side expression */`
## `PhpParser\Node\Expr\BinaryOp\Minus`
### Example PHP Code
```php
### Public Properties
* `$left` - `/** @var Expr The left hand side expression */`
* `$right` - `/** @var Expr The right hand side expression */`
## `PhpParser\Node\Expr\BinaryOp\NotEqual`
### Example PHP Code
```php
### Public Properties
* `$left` - `/** @var Expr The left hand side expression */`
* `$right` - `/** @var Expr The right hand side expression */`
## `PhpParser\Node\Expr\BinaryOp\NotIdentical`
### Example PHP Code
```php
### Public Properties
* `$left` - `/** @var Expr The left hand side expression */`
* `$right` - `/** @var Expr The right hand side expression */`
## `PhpParser\Node\Expr\BinaryOp\Spaceship`
### Example PHP Code
```php
10
```
### Public Properties
* `$left` - `/** @var Expr The left hand side expression */`
* `$right` - `/** @var Expr The right hand side expression */`
## `PhpParser\Node\Expr\BooleanNot`
### Example PHP Code
```php
### Public Properties
* `$expr` - `/** @var Expr Expression */`
## `PhpParser\Node\Expr\Cast\Array_`
### Example PHP Code
```php
### Public Properties
* `$expr` - `/** @var Expr Expression */`
## `PhpParser\Node\Expr\Cast\Bool_`
### Example PHP Code
```php
### Public Properties
* `$expr` - `/** @var Expr Expression */`
## `PhpParser\Node\Expr\Cast\Int_`
### Example PHP Code
```php
### Public Properties
* `$expr` - `/** @var Expr Expression */`
## `PhpParser\Node\Expr\Cast\String_`
### Example PHP Code
```php
### Public Properties
* `$expr` - `/** @var Expr Expression */`
## `PhpParser\Node\Expr\ClassConstFetch`
### Example PHP Code
```php
### Public Properties
* `$class` - `/** @var Name|Expr Class name */`
* `$name` - `/** @var Identifier|Error Constant name */`
## `PhpParser\Node\Expr\ClosureUse`
### Example PHP Code
```php
### Public Properties
* `$var` - `/** @var Expr\Variable Variable to use */`
* `$byRef` - `/** @var bool Whether to use by reference */`
## `PhpParser\Node\Expr\ConstFetch`
### Example PHP Code
```php
### Public Properties
* `$name` - `/** @var Name Constant name */`
## `PhpParser\Node\Expr\Empty_`
### Example PHP Code
```php
### Public Properties
* `$expr` - `/** @var Expr Expression */`
## `PhpParser\Node\Expr\Eval_`
### Example PHP Code
```php
### Public Properties
* `$expr` - `/** @var Expr Expression */`
## `PhpParser\Node\Expr\FuncCall`
### Example PHP Code
```php
### Public Properties
* `$name` - `/** @var Node\Name|Expr Function name */`
* `$args` - `/** @var array Arguments */`
## `PhpParser\Node\Expr\Include_`
### Example PHP Code
```php
```php
### Public Properties
* `$expr` - `/** @var Expr Expression */`
* `$type` - `/** @var int Type of include */`
## `PhpParser\Node\Expr\Instanceof_`
### Example PHP Code
```php
### Public Properties
* `$expr` - `/** @var Expr Expression */`
* `$class` - `/** @var Name|Expr Class name */`
## `PhpParser\Node\Expr\Isset_`
### Example PHP Code
```php
### Public Properties
* `$vars` - `/** @var Expr[] Variables */`
## `PhpParser\Node\Expr\List_`
### Example PHP Code
```php
### Public Properties
* `$items` - `/** @var (ArrayItem|null)[] List of items to assign to */`
## `PhpParser\Node\Expr\Match_`
### Example PHP Code
```php
'yes',
}
```
### Public Properties
* `$cond` - `/** @var Node\Expr */`
* `$arms` - `/** @var MatchArm[] */`
## `PhpParser\Node\Expr\MethodCall`
### Example PHP Code
```php
methodName()
```
```php
methodName('yes')->nextMethodName()
```
```php
someProperty->methodName()
```
```php
methodName('yes', 'maybe')
```
### Public Properties
* `$var` - `/** @var Expr Variable holding object */`
* `$name` - `/** @var Identifier|Expr Method name */`
* `$args` - `/** @var array Arguments */`
## `PhpParser\Node\Expr\New_`
### Example PHP Code
```php
```php
### Public Properties
* `$class` - `/** @var Node\Name|Expr|Node\Stmt\Class_ Class name */`
* `$args` - `/** @var array Arguments */`
## `PhpParser\Node\Expr\NullsafeMethodCall`
### Example PHP Code
```php
methodName()
```
### Public Properties
* `$var` - `/** @var Expr Variable holding object */`
* `$name` - `/** @var Identifier|Expr Method name */`
* `$args` - `/** @var array Arguments */`
## `PhpParser\Node\Expr\NullsafePropertyFetch`
### Example PHP Code
```php
someProperty
```
### Public Properties
* `$var` - `/** @var Expr Variable holding object */`
* `$name` - `/** @var Identifier|Expr Property name */`
## `PhpParser\Node\Expr\PropertyFetch`
### Example PHP Code
```php
propertyName
```
### Public Properties
* `$var` - `/** @var Expr Variable holding object */`
* `$name` - `/** @var Identifier|Expr Property name */`
## `PhpParser\Node\Expr\StaticCall`
### Example PHP Code
```php
### Public Properties
* `$class` - `/** @var Node\Name|Expr Class name */`
* `$name` - `/** @var Identifier|Expr Method name */`
* `$args` - `/** @var array Arguments */`
## `PhpParser\Node\Expr\StaticPropertyFetch`
### Example PHP Code
```php
### Public Properties
* `$class` - `/** @var Name|Expr Class name */`
* `$name` - `/** @var VarLikeIdentifier|Expr Property name */`
## `PhpParser\Node\Expr\Ternary`
### Example PHP Code
```php
### Public Properties
* `$cond` - `/** @var Expr Condition */`
* `$if` - `/** @var null|Expr Expression for true */`
* `$else` - `/** @var Expr Expression for false */`
## `PhpParser\Node\Expr\Throw_`
### Example PHP Code
```php
### Public Properties
* `$expr` - `/** @var Node\Expr Expression */`
## `PhpParser\Node\Expr\Variable`
### Example PHP Code
```php
### Public Properties
* `$name` - `/** @var string|Expr Name */`
## `PhpParser\Node\MatchArm`
### Example PHP Code
```php
'yes'
```
### Public Properties
* `$conds` - `/** @var null|Node\Expr[] */`
* `$body` - `/** @var Node\Expr */`
## `PhpParser\Node\Name`
### Example PHP Code
```php
### Public Properties
* `$parts` - `/**
* @var string[] Parts of the name
* @deprecated Use getParts() instead
*/`
* `$specialClassNames` - ``
## `PhpParser\Node\Name\FullyQualified`
### Example PHP Code
```php
### Public Properties
* `$parts` - `/**
* @var string[] Parts of the name
* @deprecated Use getParts() instead
*/`
## `PhpParser\Node\NullableType`
### Example PHP Code
```php
### Public Properties
* `$type` - `/** @var Identifier|Name Type */`
## `PhpParser\Node\Param`
### Example PHP Code
```php
### Public Properties
* `$type` - `/** @var null|Identifier|Name|ComplexType Type declaration */`
* `$byRef` - `/** @var bool Whether parameter is passed by reference */`
* `$variadic` - `/** @var bool Whether this is a variadic argument */`
* `$var` - `/** @var Expr\Variable|Expr\Error Parameter variable */`
* `$default` - `/** @var null|Expr Default value */`
* `$flags` - `/** @var int */`
* `$attrGroups` - `/** @var AttributeGroup[] PHP attribute groups */`
## `PhpParser\Node\Scalar\DNumber`
### Example PHP Code
```php
### Public Properties
* `$value` - `/** @var float Number value */`
## `PhpParser\Node\Scalar\Encapsed`
### Example PHP Code
```php
### Public Properties
* `$parts` - `/** @var Expr[] list of string parts */`
## `PhpParser\Node\Scalar\LNumber`
### Example PHP Code
```php
### Public Properties
* `$value` - `/** @var int Number value */`
## `PhpParser\Node\Scalar\String_`
### Example PHP Code
```php
### Public Properties
* `$value` - `/** @var string String value */`
* `$replacements` - ``
## `PhpParser\Node\Stmt\ClassConst`
### Example PHP Code
```php
### Public Properties
* `$flags` - `/** @var int Modifiers */`
* `$consts` - `/** @var Node\Const_[] Constant declarations */`
* `$attrGroups` - `/** @var Node\AttributeGroup[] */`
## `PhpParser\Node\Stmt\ClassMethod`
### Example PHP Code
```php
flags = Class_::MODIFIER_PUBLIC;
return $classMethod;
```
↓
```php
public function methodName()
{
}
```
```php
flags = Class_::MODIFIER_PRIVATE;
$param = new Param(new Variable('paramName'));
$classMethod->params = [$param];
$classMethod->returnType = new Identifier('string');
return $classMethod;
```
↓
```php
private function methodName($paramName) : string
{
}
```
```php
flags = Class_::MODIFIER_PUBLIC;
$variable = new Variable('some');
$number = new LNumber(10000);
$assign = new Assign($variable, $number);
$classMethod->stmts[] = new Expression($assign);
return $classMethod;
```
↓
```php
public function methodName()
{
$some = 10000;
}
```
### Public Properties
* `$flags` - `/** @var int Flags */`
* `$byRef` - `/** @var bool Whether to return by reference */`
* `$name` - `/** @var Node\Identifier Name */`
* `$params` - `/** @var Node\Param[] Parameters */`
* `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */`
* `$stmts` - `/** @var Node\Stmt[]|null Statements */`
* `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */`
* `$magicNames` - ``
## `PhpParser\Node\Stmt\Class_`
### Example PHP Code
```php
```php
flags |= Class_::MODIFIER_FINAL;
return $class;
```
↓
```php
final class ClassName
{
}
```
```php
flags = Class_::MODIFIER_FINAL;
$class->extends = new FullyQualified('ParentClass');
return $class;
```
↓
```php
final class ClassName extends \ParentClass
{
}
```
### Public Properties
* `$flags` - `/** @var int Type */`
* `$extends` - `/** @var null|Node\Name Name of extended class */`
* `$implements` - `/** @var Node\Name[] Names of implemented interfaces */`
* `$name` - `/** @var Node\Identifier|null Name */`
* `$stmts` - `/** @var Node\Stmt[] Statements */`
* `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */`
* `$namespacedName` - `/** @var Node\Name|null Namespaced name (if using NameResolver) */`
## `PhpParser\Node\Stmt\Const_`
### Example PHP Code
```php
### Public Properties
* `$consts` - `/** @var Node\Const_[] Constant declarations */`
## `PhpParser\Node\Stmt\Declare_`
### Example PHP Code
```php
### Public Properties
* `$declares` - `/** @var DeclareDeclare[] List of declares */`
* `$stmts` - `/** @var Node\Stmt[]|null Statements */`
## `PhpParser\Node\Stmt\Do_`
### Example PHP Code
```php
### Public Properties
* `$stmts` - `/** @var Node\Stmt[] Statements */`
* `$cond` - `/** @var Node\Expr Condition */`
## `PhpParser\Node\Stmt\Echo_`
### Example PHP Code
```php
### Public Properties
* `$exprs` - `/** @var Node\Expr[] Expressions */`
## `PhpParser\Node\Stmt\ElseIf_`
### Example PHP Code
```php
### Public Properties
* `$cond` - `/** @var Node\Expr Condition */`
* `$stmts` - `/** @var Node\Stmt[] Statements */`
## `PhpParser\Node\Stmt\Foreach_`
### Example PHP Code
```php
### Public Properties
* `$expr` - `/** @var Node\Expr Expression to iterate */`
* `$keyVar` - `/** @var null|Node\Expr Variable to assign key to */`
* `$byRef` - `/** @var bool Whether to assign value by reference */`
* `$valueVar` - `/** @var Node\Expr Variable to assign value to */`
* `$stmts` - `/** @var Node\Stmt[] Statements */`
## `PhpParser\Node\Stmt\Function_`
### Example PHP Code
```php
### Public Properties
* `$byRef` - `/** @var bool Whether function returns by reference */`
* `$name` - `/** @var Node\Identifier Name */`
* `$params` - `/** @var Node\Param[] Parameters */`
* `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */`
* `$stmts` - `/** @var Node\Stmt[] Statements */`
* `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */`
* `$namespacedName` - `/** @var Node\Name|null Namespaced name (if using NameResolver) */`
## `PhpParser\Node\Stmt\If_`
### Example PHP Code
```php
### Public Properties
* `$cond` - `/** @var Node\Expr Condition expression */`
* `$stmts` - `/** @var Node\Stmt[] Statements */`
* `$elseifs` - `/** @var ElseIf_[] Elseif clauses */`
* `$else` - `/** @var null|Else_ Else clause */`
## `PhpParser\Node\Stmt\InlineHTML`
### Example PHP Code
```php
feel');
```
↓
```php
?>
feel
### Public Properties
* `$value` - `/** @var string String */`
## `PhpParser\Node\Stmt\Interface_`
### Example PHP Code
```php
### Public Properties
* `$extends` - `/** @var Node\Name[] Extended interfaces */`
* `$name` - `/** @var Node\Identifier|null Name */`
* `$stmts` - `/** @var Node\Stmt[] Statements */`
* `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */`
* `$namespacedName` - `/** @var Node\Name|null Namespaced name (if using NameResolver) */`
## `PhpParser\Node\Stmt\Label`
### Example PHP Code
```php
### Public Properties
* `$name` - `/** @var Identifier Name */`
## `PhpParser\Node\Stmt\Property`
### Example PHP Code
```php
```php
```php
### Public Properties
* `$flags` - `/** @var int Modifiers */`
* `$props` - `/** @var PropertyProperty[] Properties */`
* `$type` - `/** @var null|Identifier|Name|ComplexType Type declaration */`
* `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */`
## `PhpParser\Node\Stmt\PropertyProperty`
### Example PHP Code
```php
stmts[] = $property;
return $propertyProperty;
```
↓
```php
$someProperty
```
### Public Properties
* `$name` - `/** @var Node\VarLikeIdentifier Name */`
* `$default` - `/** @var null|Node\Expr Default */`
## `PhpParser\Node\Stmt\StaticVar`
### Example PHP Code
```php
### Public Properties
* `$var` - `/** @var Expr\Variable Variable */`
* `$default` - `/** @var null|Node\Expr Default value */`
## `PhpParser\Node\Stmt\Static_`
### Example PHP Code
```php
### Public Properties
* `$vars` - `/** @var StaticVar[] Variable definitions */`
## `PhpParser\Node\Stmt\Switch_`
### Example PHP Code
```php
### Public Properties
* `$cond` - `/** @var Node\Expr Condition */`
* `$cases` - `/** @var Case_[] Case list */`
## `PhpParser\Node\Stmt\Throw_`
### Example PHP Code
```php
### Public Properties
* `$expr` - `/** @var Node\Expr Expression */`
## `PhpParser\Node\Stmt\TraitUse`
### Example PHP Code
```php
### Public Properties
* `$traits` - `/** @var Node\Name[] Traits */`
* `$adaptations` - `/** @var TraitUseAdaptation[] Adaptations */`
## `PhpParser\Node\Stmt\TraitUseAdaptation\Alias`
### Example PHP Code
```php
### Public Properties
* `$newModifier` - `/** @var null|int New modifier */`
* `$newName` - `/** @var null|Node\Identifier New name */`
* `$trait` - `/** @var Node\Name|null Trait name */`
* `$method` - `/** @var Node\Identifier Method name */`
## `PhpParser\Node\Stmt\Trait_`
### Example PHP Code
```php
### Public Properties
* `$name` - `/** @var Node\Identifier|null Name */`
* `$stmts` - `/** @var Node\Stmt[] Statements */`
* `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */`
* `$namespacedName` - `/** @var Node\Name|null Namespaced name (if using NameResolver) */`
## `PhpParser\Node\Stmt\TryCatch`
### Example PHP Code
```php
### Public Properties
* `$stmts` - `/** @var Node\Stmt[] Statements */`
* `$catches` - `/** @var Catch_[] Catches */`
* `$finally` - `/** @var null|Finally_ Optional finally node */`
## `PhpParser\Node\Stmt\Unset_`
### Example PHP Code
```php
### Public Properties
* `$vars` - `/** @var Node\Expr[] Variables to unset */`
## `PhpParser\Node\Stmt\Use_`
### Example PHP Code
```php
### Public Properties
* `$type` - `/** @var int Type of alias */`
* `$uses` - `/** @var UseUse[] Aliases */`
## `PhpParser\Node\Stmt\While_`
### Example PHP Code
```php
### Public Properties
* `$cond` - `/** @var Node\Expr Condition */`
* `$stmts` - `/** @var Node\Stmt[] Statements */`
## `PhpParser\Node\UnionType`
### Example PHP Code
```php
### Public Properties
* `$types` - `/** @var (Identifier|Name|IntersectionType)[] Types */`