Here you can find overview of commonly used nodes and how to build PHP code from them. For all nodes, check php-parser code.
<?phpdeclare(strict_types=1); usePhpParser\Node\Const_; usePhpParser\Node\Scalar\String_; returnnewConst_('CONSTANT_NAME', newString_('default'));
↓
CONSTANT_NAME = 'default'
$name
-/** @var Identifier Name */
$value
-/** @var Expr Value */
$namespacedName
-/** @var Name|null Namespaced name (if using NameResolver) */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\ArrayDimFetch; usePhpParser\Node\Expr\Variable; usePhpParser\Node\Scalar\LNumber; $variable = newVariable('variableName'); $dimension = newLNumber(0); returnnewArrayDimFetch($variable, $dimension);
↓
$variableName[0]
$var
-/** @var Expr Variable */
$dim
-/** @var null|Expr Array index / dim */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\ArrayItem; usePhpParser\Node\Expr\Variable; usePhpParser\Node\Scalar\String_; $value = newVariable('Tom'); $key = newString_('name'); returnnewArrayItem($value, $key);
↓
'name' => $Tom
$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 */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Array_; usePhpParser\Node\Expr\ArrayItem; usePhpParser\Node\Expr\Variable; usePhpParser\Node\Scalar\String_; $value = newVariable('Tom'); $key = newString_('name'); $arrayItem = newArrayItem($value, $key); returnnewArray_([$arrayItem]);
↓
array('name' => $Tom)
$items
-/** @var (ArrayItem|null)[] Items */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\ArrowFunction; usePhpParser\Node\Scalar\LNumber; $subNodes['expr'] = newLNumber(1); returnnewArrowFunction($subNodes);
↓
fn() => 1
$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[] */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Assign; usePhpParser\Node\Expr\Variable; usePhpParser\Node\Scalar\String_; $variable = newVariable('variableName'); $value = newString_('some value'); returnnewAssign($variable, $value);
↓
$variableName = 'some value'
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Assign; usePhpParser\Node\Expr\PropertyFetch; usePhpParser\Node\Expr\Variable; usePhpParser\Node\Scalar\String_; $propertyFetch = newPropertyFetch(newVariable('someObject'), 'someProperty'); $value = newString_('some value'); returnnewAssign($propertyFetch, $value);
↓
$someObject->someProperty = 'some value'
$var
-/** @var Expr Variable */
$expr
-/** @var Expr Expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\AssignOp\Coalesce; usePhpParser\Node\Scalar\LNumber; $left = newLNumber(5); $right = newLNumber(10); returnnewCoalesce($left, $right);
↓
5 ??= 10
$var
-/** @var Expr Variable */
$expr
-/** @var Expr Expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\AssignOp\Concat; usePhpParser\Node\Scalar\LNumber; $left = newLNumber(5); $right = newLNumber(10); returnnewConcat($left, $right);
↓
5 .= 10
$var
-/** @var Expr Variable */
$expr
-/** @var Expr Expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\BinaryOp\BooleanAnd; usePhpParser\Node\Scalar\LNumber; $left = newLNumber(5); $right = newLNumber(10); returnnewBooleanAnd($left, $right);
↓
5 && 10
$left
-/** @var Expr The left hand side expression */
$right
-/** @var Expr The right hand side expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\BinaryOp\Coalesce; usePhpParser\Node\Scalar\LNumber; $left = newLNumber(5); $right = newLNumber(10); returnnewCoalesce($left, $right);
↓
5 ?? 10
$left
-/** @var Expr The left hand side expression */
$right
-/** @var Expr The right hand side expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\BinaryOp\Concat; usePhpParser\Node\Scalar\LNumber; $left = newLNumber(5); $right = newLNumber(10); returnnewConcat($left, $right);
↓
5 . 10
$left
-/** @var Expr The left hand side expression */
$right
-/** @var Expr The right hand side expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\BinaryOp\Equal; usePhpParser\Node\Scalar\LNumber; $left = newLNumber(5); $right = newLNumber(10); returnnewEqual($left, $right);
↓
5 == 10
$left
-/** @var Expr The left hand side expression */
$right
-/** @var Expr The right hand side expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\BinaryOp\Identical; usePhpParser\Node\Scalar\LNumber; $left = newLNumber(5); $right = newLNumber(10); returnnewIdentical($left, $right);
↓
5 === 10
$left
-/** @var Expr The left hand side expression */
$right
-/** @var Expr The right hand side expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\BinaryOp\Minus; usePhpParser\Node\Scalar\LNumber; $left = newLNumber(5); $right = newLNumber(10); returnnewMinus($left, $right);
↓
5 - 10
$left
-/** @var Expr The left hand side expression */
$right
-/** @var Expr The right hand side expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\BinaryOp\NotEqual; usePhpParser\Node\Scalar\LNumber; $left = newLNumber(5); $right = newLNumber(10); returnnewNotEqual($left, $right);
↓
5 != 10
$left
-/** @var Expr The left hand side expression */
$right
-/** @var Expr The right hand side expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\BinaryOp\NotIdentical; usePhpParser\Node\Scalar\LNumber; $left = newLNumber(5); $right = newLNumber(10); returnnewNotIdentical($left, $right);
↓
5 !== 10
$left
-/** @var Expr The left hand side expression */
$right
-/** @var Expr The right hand side expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\BinaryOp\Spaceship; usePhpParser\Node\Scalar\LNumber; $left = newLNumber(5); $right = newLNumber(10); returnnewSpaceship($left, $right);
↓
5 <=> 10
$left
-/** @var Expr The left hand side expression */
$right
-/** @var Expr The right hand side expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\BooleanNot; usePhpParser\Node\Expr\Variable; $variable = newVariable('isEligible'); returnnewBooleanNot($variable);
↓
!$isEligible
$expr
-/** @var Expr Expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Cast\Array_; usePhpParser\Node\Expr\Variable; $expr = newVariable('variableName'); returnnewArray_($expr);
↓
(array) $variableName
$expr
-/** @var Expr Expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Cast\Bool_; usePhpParser\Node\Expr\Variable; $expr = newVariable('variableName'); returnnewBool_($expr);
↓
(bool) $variableName
$expr
-/** @var Expr Expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Cast\Int_; usePhpParser\Node\Expr\Variable; $expr = newVariable('variableName'); returnnewInt_($expr);
↓
(int) $variableName
$expr
-/** @var Expr Expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Cast\String_; usePhpParser\Node\Expr\Variable; $expr = newVariable('variableName'); returnnewString_($expr);
↓
(string) $variableName
$expr
-/** @var Expr Expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\ClassConstFetch; usePhpParser\Node\Name\FullyQualified; $class = newFullyQualified('SomeClassName'); returnnewClassConstFetch($class, 'SOME_CONSTANT');
↓
\SomeClassName::SOME_CONSTANT
$class
-/** @var Name|Expr Class name */
$name
-/** @var Identifier|Error Constant name */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\ClosureUse; usePhpParser\Node\Expr\Variable; $variable = newVariable('variableName'); returnnewClosureUse($variable);
↓
$variableName
$var
-/** @var Expr\Variable Variable to use */
$byRef
-/** @var bool Whether to use by reference */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\ConstFetch; usePhpParser\Node\Name; $name = newName('true'); returnnewConstFetch($name);
↓
true
$name
-/** @var Name Constant name */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Empty_; usePhpParser\Node\Expr\Variable; $variable = newVariable('variableName'); returnnewEmpty_($variable);
↓
empty($variableName)
$expr
-/** @var Expr Expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Eval_; usePhpParser\Node\Scalar\String_; $string = newString_('Some php code'); returnnewEval_(newString_('Some php code'));
↓
eval('Some php code')
$expr
-/** @var Expr Expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Arg; usePhpParser\Node\Expr\FuncCall; usePhpParser\Node\Expr\Variable; usePhpParser\Node\Name; $args = [newArg(newVariable('someVariable'))]; returnnewFuncCall(newName('func_call'), $args);
↓
func_call($someVariable)
$name
-/** @var Node\Name|Expr Function name */
$args
-/** @var array<Node\Arg|Node\VariadicPlaceholder> Arguments */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Include_; usePhpParser\Node\Expr\Variable; $variable = newVariable('variableName'); returnnewInclude_($variable, Include_::TYPE_INCLUDE);
↓
include$variableName
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Include_; usePhpParser\Node\Expr\Variable; $variable = newVariable('variableName'); returnnewInclude_($variable, Include_::TYPE_REQUIRE_ONCE);
↓
require_once$variableName
$expr
-/** @var Expr Expression */
$type
-/** @var int Type of include */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Instanceof_; usePhpParser\Node\Expr\Variable; usePhpParser\Node\Name\FullyQualified; $variable = newVariable('variableName'); $class = newFullyQualified('SomeClassName'); returnnewInstanceof_($variable, $class);
↓
$variableNameinstanceof \SomeClassName
$expr
-/** @var Expr Expression */
$class
-/** @var Name|Expr Class name */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Isset_; usePhpParser\Node\Expr\Variable; $variable = newVariable('variableName'); returnnewIsset_([$variable]);
↓
isset($variableName)
$vars
-/** @var Expr[] Variables */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\ArrayItem; usePhpParser\Node\Expr\List_; usePhpParser\Node\Expr\Variable; $variable = newVariable('variableName'); $anotherVariable = newVariable('anotherVariableName'); $arrayItems = [newArrayItem($variable), newArrayItem($anotherVariable)]; returnnewList_($arrayItems);
↓
list($variableName, $anotherVariableName)
$items
-/** @var (ArrayItem|null)[] List of items to assign to */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Match_; usePhpParser\Node\Expr\Variable; usePhpParser\Node\MatchArm; usePhpParser\Node\Scalar\LNumber; usePhpParser\Node\Scalar\String_; $variable = newVariable('variableName'); $body = newString_('yes'); $cond = newLNumber(1); $matchArm = newMatchArm([$cond], $body); returnnewMatch_($variable, [$matchArm]);
↓
match ($variableName) { 1 => 'yes', }
$cond
-/** @var Node\Expr */
$arms
-/** @var MatchArm[] */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\MethodCall; usePhpParser\Node\Expr\Variable; $variable = newVariable('someObject'); returnnewMethodCall($variable, 'methodName');
↓
$someObject->methodName()
<?phpdeclare(strict_types=1); usePhpParser\Node\Arg; usePhpParser\Node\Expr\MethodCall; usePhpParser\Node\Expr\Variable; usePhpParser\Node\Scalar\String_; $variable = newVariable('someObject'); $args = []; $args[] = newArg(newString_('yes')); $methodCall = newMethodCall($variable, 'methodName', $args); $nestedMethodCall = newMethodCall($methodCall, 'nextMethodName'); return$nestedMethodCall;
↓
$someObject->methodName('yes')->nextMethodName()
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\MethodCall; usePhpParser\Node\Expr\PropertyFetch; usePhpParser\Node\Expr\Variable; $thisVariable = newVariable('this'); $propertyFetch = newPropertyFetch($thisVariable, 'someProperty'); returnnewMethodCall($propertyFetch, 'methodName');
↓
$this->someProperty->methodName()
<?phpdeclare(strict_types=1); usePhpParser\Node\Arg; usePhpParser\Node\Expr\MethodCall; usePhpParser\Node\Expr\Variable; usePhpParser\Node\Scalar\String_; $variable = newVariable('someObject'); $args = []; $args[] = newArg(newString_('yes')); $args[] = newArg(newString_('maybe')); returnnewMethodCall($variable, 'methodName', $args);
↓
$someObject->methodName('yes', 'maybe')
$var
-/** @var Expr Variable holding object */
$name
-/** @var Identifier|Expr Method name */
$args
-/** @var array<Arg|VariadicPlaceholder> Arguments */
<?phpdeclare(strict_types=1); // anonymous classusePhpParser\Node\Expr\New_; usePhpParser\Node\Stmt\Class_; $class = newClass_(null); returnnewNew_($class);
↓
newclass { }
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\New_; usePhpParser\Node\Name; $class = newName('SomeClass'); returnnewNew_($class);
↓
newSomeClass()
$class
-/** @var Node\Name|Expr|Node\Stmt\Class_ Class name */
$args
-/** @var array<Arg|VariadicPlaceholder> Arguments */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\NullsafeMethodCall; usePhpParser\Node\Expr\Variable; $variable = newVariable('variableName'); returnnewNullsafeMethodCall($variable, 'methodName');
↓
$variableName?->methodName()
$var
-/** @var Expr Variable holding object */
$name
-/** @var Identifier|Expr Method name */
$args
-/** @var array<Arg|VariadicPlaceholder> Arguments */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\NullsafePropertyFetch; usePhpParser\Node\Expr\Variable; $variable = newVariable('variableName'); returnnewNullsafePropertyFetch($variable, 'someProperty');
↓
$variableName?->someProperty
$var
-/** @var Expr Variable holding object */
$name
-/** @var Identifier|Expr Property name */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\PropertyFetch; usePhpParser\Node\Expr\Variable; $variable = newVariable('variableName'); returnnewPropertyFetch($variable, 'propertyName');
↓
$variableName->propertyName
$var
-/** @var Expr Variable holding object */
$name
-/** @var Identifier|Expr Property name */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\StaticCall; usePhpParser\Node\Name\FullyQualified; $fullyQualified = newFullyQualified('ClassName'); returnnewStaticCall($fullyQualified, 'methodName');
↓
\ClassName::methodName()
$class
-/** @var Node\Name|Expr Class name */
$name
-/** @var Identifier|Expr Method name */
$args
-/** @var array<Arg|VariadicPlaceholder> Arguments */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\StaticPropertyFetch; usePhpParser\Node\Name\FullyQualified; $class = newFullyQualified('StaticClassName'); returnnewStaticPropertyFetch($class, 'someProperty');
↓
\StaticClassName::$someProperty
$class
-/** @var Name|Expr Class name */
$name
-/** @var VarLikeIdentifier|Expr Property name */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\ConstFetch; usePhpParser\Node\Expr\Ternary; usePhpParser\Node\Expr\Variable; usePhpParser\Node\Name; $variable = newVariable('variableName'); $trueConstFetch = newConstFetch(newName('true')); $falseConstFetch = newConstFetch(newName('false')); returnnewTernary($variable, $trueConstFetch, $falseConstFetch);
↓
$variableName ? true : false
$cond
-/** @var Expr Condition */
$if
-/** @var null|Expr Expression for true */
$else
-/** @var Expr Expression for false */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Throw_; usePhpParser\Node\Scalar\String_; $string = newString_('some string'); returnnewThrow_($string);
↓
throw'some string'
$expr
-/** @var Node\Expr Expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Variable; returnnewVariable('variableName');
↓
$variableName
$name
-/** @var string|Expr Name */
<?phpdeclare(strict_types=1); usePhpParser\Node\MatchArm; usePhpParser\Node\Scalar\LNumber; usePhpParser\Node\Scalar\String_; $conds = [newLNumber(1)]; $body = newString_('yes'); returnnewMatchArm($conds, $body);
↓
1 => 'yes'
$conds
-/** @var null|Node\Expr[] */
$body
-/** @var Node\Expr */
<?phpdeclare(strict_types=1); usePhpParser\Node\Name; returnnewName('shortName');
↓
shortName
$parts
- `/**- @var string[] Parts of the name
- @deprecated Use getParts() instead */`
$specialClassNames
- ``
<?phpdeclare(strict_types=1); usePhpParser\Node\Name\FullyQualified; returnnewFullyQualified('SomeNamespace\ShortName');
↓
\SomeNamespace\ShortName
$parts
- `/**- @var string[] Parts of the name
- @deprecated Use getParts() instead */`
<?phpdeclare(strict_types=1); usePhpParser\Node\NullableType; returnnewNullableType('SomeType');
↓
?SomeType
$type
-/** @var Identifier|Name Type */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Variable; usePhpParser\Node\Param; $variable = newVariable('variableName'); returnnewParam($variable);
↓
$variableName
$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 */
<?phpdeclare(strict_types=1); usePhpParser\Node\Scalar\DNumber; returnnewDNumber(10.5);
↓
10.5
$value
-/** @var float Number value */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Variable; usePhpParser\Node\Scalar\Encapsed; returnnewEncapsed([newVariable('variableName')]);
↓
"{$variableName}"
$parts
-/** @var Expr[] list of string parts */
<?phpdeclare(strict_types=1); usePhpParser\Node\Scalar\LNumber; returnnewLNumber(1000);
↓
1000
$value
-/** @var int Number value */
<?phpdeclare(strict_types=1); usePhpParser\Node\Scalar\String_; returnnewString_('some string');
↓
'some string'
$value
-/** @var string String value */
$replacements
- ``
<?phpdeclare(strict_types=1); usePhpParser\Node\Const_; usePhpParser\Node\Scalar\String_; usePhpParser\Node\Stmt\Class_; usePhpParser\Node\Stmt\ClassConst; $defaultValue = newString_('default value'); $const = newConst_('SOME_CLASS_CONSTANT', $defaultValue); returnnewClassConst([$const], Class_::MODIFIER_PUBLIC);
↓
publicconstSOME_CLASS_CONSTANT = 'default value';
$flags
-/** @var int Modifiers */
$consts
-/** @var Node\Const_[] Constant declarations */
$attrGroups
-/** @var Node\AttributeGroup[] */
<?phpdeclare(strict_types=1); usePhpParser\Node\Stmt\Class_; usePhpParser\Node\Stmt\ClassMethod; $classMethod = newClassMethod('methodName'); $classMethod->flags = Class_::MODIFIER_PUBLIC; return$classMethod;
↓
publicfunctionmethodName() { }
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Variable; usePhpParser\Node\Identifier; usePhpParser\Node\Param; usePhpParser\Node\Stmt\Class_; usePhpParser\Node\Stmt\ClassMethod; $classMethod = newClassMethod('methodName'); $classMethod->flags = Class_::MODIFIER_PRIVATE; $param = newParam(newVariable('paramName')); $classMethod->params = [$param]; $classMethod->returnType = newIdentifier('string'); return$classMethod;
↓
privatefunctionmethodName($paramName) : string { }
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Assign; usePhpParser\Node\Expr\Variable; usePhpParser\Node\Scalar\LNumber; usePhpParser\Node\Stmt\Class_; usePhpParser\Node\Stmt\ClassMethod; usePhpParser\Node\Stmt\Expression; $classMethod = newClassMethod('methodName'); $classMethod->flags = Class_::MODIFIER_PUBLIC; $variable = newVariable('some'); $number = newLNumber(10000); $assign = newAssign($variable, $number); $classMethod->stmts[] = newExpression($assign); return$classMethod;
↓
publicfunctionmethodName() { $some = 10000; }
$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
- ``
<?phpdeclare(strict_types=1); usePhpParser\Node\Stmt\Class_; returnnewClass_('ClassName');
↓
class ClassName { }
<?phpdeclare(strict_types=1); usePhpParser\Node\Stmt\Class_; $class = newClass_('ClassName'); $class->flags |= Class_::MODIFIER_FINAL; return$class;
↓
finalclass ClassName { }
<?phpdeclare(strict_types=1); usePhpParser\Node\Name\FullyQualified; usePhpParser\Node\Stmt\Class_; $class = newClass_('ClassName'); $class->flags = Class_::MODIFIER_FINAL; $class->extends = newFullyQualified('ParentClass'); return$class;
↓
finalclass ClassName extends \ParentClass { }
$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) */
<?phpdeclare(strict_types=1); usePhpParser\Node\Const_; usePhpParser\Node\Scalar\String_; usePhpParser\Node\Stmt\Const_asConstStmt; $consts = [newConst_('CONSTANT_IN_CLASS', newString_('default value'))]; returnnewConstStmt($consts);
↓
constCONSTANT_IN_CLASS = 'default value';
$consts
-/** @var Node\Const_[] Constant declarations */
<?phpdeclare(strict_types=1); usePhpParser\Node\Scalar\LNumber; usePhpParser\Node\Stmt\Declare_; usePhpParser\Node\Stmt\DeclareDeclare; $declareDeclare = newDeclareDeclare('strict_types', newLNumber(1)); returnnewDeclare_([$declareDeclare]);
↓
declare (strict_types=1);
$declares
-/** @var DeclareDeclare[] List of declares */
$stmts
-/** @var Node\Stmt[]|null Statements */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Variable; usePhpParser\Node\Stmt\Do_; $variable = newVariable('variableName'); returnnewDo_($variable);
↓
do { } while ($variableName);
$stmts
-/** @var Node\Stmt[] Statements */
$cond
-/** @var Node\Expr Condition */
<?phpdeclare(strict_types=1); usePhpParser\Node\Scalar\String_; usePhpParser\Node\Stmt\Echo_; $string = newString_('hello'); returnnewEcho_([$string]);
↓
echo'hello';
$exprs
-/** @var Node\Expr[] Expressions */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\ConstFetch; usePhpParser\Node\Name; usePhpParser\Node\Stmt\ElseIf_; usePhpParser\Node\Stmt\Return_; $name = newName('true'); $constFetch = newConstFetch($name); $stmt = newReturn_(); returnnewElseIf_($constFetch, [$stmt]);
↓
elseif (true) { return; }
$cond
-/** @var Node\Expr Condition */
$stmts
-/** @var Node\Stmt[] Statements */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Variable; usePhpParser\Node\Stmt\Foreach_; $foreachedVariable = newVariable('foreachedVariableName'); $asVariable = newVariable('asVariable'); returnnewForeach_($foreachedVariable, $asVariable);
↓
foreach ($foreachedVariableNameas$asVariable) { }
$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 */
<?phpdeclare(strict_types=1); usePhpParser\Node\Stmt\Function_; returnnewFunction_('some_function');
↓
functionsome_function() { }
$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) */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\ConstFetch; usePhpParser\Node\Name; usePhpParser\Node\Stmt\If_; $cond = newConstFetch(newName('true')); returnnewIf_($cond);
↓
if (true) { }
$cond
-/** @var Node\Expr Condition expression */
$stmts
-/** @var Node\Stmt[] Statements */
$elseifs
-/** @var ElseIf_[] Elseif clauses */
$else
-/** @var null|Else_ Else clause */
<?phpdeclare(strict_types=1); usePhpParser\Node\Stmt\InlineHTML; returnnewInlineHTML('<strong>feel</strong>');
↓
?> <strong>feel</strong><?php
$value
-/** @var string String */
<?phpdeclare(strict_types=1); usePhpParser\Node\Identifier; usePhpParser\Node\Stmt\Interface_; returnnewInterface_(newIdentifier('InterfaceName'));
↓
interface InterfaceName { }
$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) */
<?phpdeclare(strict_types=1); usePhpParser\Node\Stmt\Label; returnnewLabel('labelName');
↓
labelName:
$name
-/** @var Identifier Name */
<?phpdeclare(strict_types=1); usePhpParser\Node\Stmt\Class_; usePhpParser\Node\Stmt\Property; usePhpParser\Node\Stmt\PropertyProperty; usePhpParser\Node\VarLikeIdentifier; $propertyProperty = newPropertyProperty(newVarLikeIdentifier('propertyName')); returnnewProperty(Class_::MODIFIER_PUBLIC, [$propertyProperty], [], 'string');
↓
public string $propertyName;
<?phpdeclare(strict_types=1); usePhpParser\Node\Stmt\Class_; usePhpParser\Node\Stmt\Property; usePhpParser\Node\Stmt\PropertyProperty; usePhpParser\Node\VarLikeIdentifier; $propertyProperty = newPropertyProperty(newVarLikeIdentifier('propertyName')); returnnewProperty(Class_::MODIFIER_PUBLIC, [$propertyProperty]);
↓
public$propertyName;
<?phpdeclare(strict_types=1); usePhpParser\Node\Stmt\Class_; usePhpParser\Node\Stmt\Property; usePhpParser\Node\Stmt\PropertyProperty; $propertyProperties = [newPropertyProperty('firstProperty'), newPropertyProperty('secondProperty')]; returnnewProperty(Class_::MODIFIER_STATIC | Class_::MODIFIER_PUBLIC, $propertyProperties);
↓
publicstatic$firstProperty, $secondProperty;
$flags
-/** @var int Modifiers */
$props
-/** @var PropertyProperty[] Properties */
$type
-/** @var null|Identifier|Name|ComplexType Type declaration */
$attrGroups
-/** @var Node\AttributeGroup[] PHP attribute groups */
<?phpdeclare(strict_types=1); usePhpParser\Node\Stmt\Class_; usePhpParser\Node\Stmt\Property; usePhpParser\Node\Stmt\PropertyProperty; $class = newClass_('ClassName'); $propertyProperty = newPropertyProperty('someProperty'); $property = newProperty(Class_::MODIFIER_PRIVATE, [$propertyProperty]); $class->stmts[] = $property; return$propertyProperty;
↓
$someProperty
$name
-/** @var Node\VarLikeIdentifier Name */
$default
-/** @var null|Node\Expr Default */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Variable; usePhpParser\Node\Stmt\StaticVar; $variable = newVariable('variableName'); returnnewStaticVar($variable);
↓
$variableName
$var
-/** @var Expr\Variable Variable */
$default
-/** @var null|Node\Expr Default value */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Variable; usePhpParser\Node\Stmt\Static_; usePhpParser\Node\Stmt\StaticVar; $staticVars = [newStaticVar(newVariable('static'))]; returnnewStatic_($staticVars);
↓
static$static;
$vars
-/** @var StaticVar[] Variable definitions */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Variable; usePhpParser\Node\Scalar\LNumber; usePhpParser\Node\Stmt\Case_; usePhpParser\Node\Stmt\Switch_; $cond = newVariable('variableName'); $cases = [newCase_(newLNumber(1))]; returnnewSwitch_($cond, $cases);
↓
switch ($variableName) { case1: }
$cond
-/** @var Node\Expr Condition */
$cases
-/** @var Case_[] Case list */
<?phpdeclare(strict_types=1); usePhpParser\Node\Scalar\String_; usePhpParser\Node\Stmt\Throw_; $string = newString_('some string'); returnnewThrow_($string);
↓
throw'some string';
$expr
-/** @var Node\Expr Expression */
<?phpdeclare(strict_types=1); usePhpParser\Node\Name\FullyQualified; usePhpParser\Node\Stmt\TraitUse; returnnewTraitUse([newFullyQualified('TraitName')]);
↓
use \TraitName;
$traits
-/** @var Node\Name[] Traits */
$adaptations
-/** @var TraitUseAdaptation[] Adaptations */
<?phpdeclare(strict_types=1); usePhpParser\Node\Name\FullyQualified; usePhpParser\Node\Stmt\Class_; usePhpParser\Node\Stmt\TraitUseAdaptation\Alias; $traitFullyQualified = newFullyQualified('TraitName'); returnnewAlias($traitFullyQualified, 'method', Class_::MODIFIER_PUBLIC, 'aliasedMethod');
↓
\TraitName::method as public aliasedMethod;
$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 */
<?phpdeclare(strict_types=1); usePhpParser\Node\Stmt\Trait_; returnnewTrait_('TraitName');
↓
trait TraitName { }
$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) */
<?phpdeclare(strict_types=1); usePhpParser\Node\Name\FullyQualified; usePhpParser\Node\Scalar\String_; usePhpParser\Node\Stmt\Catch_; usePhpParser\Node\Stmt\Echo_; usePhpParser\Node\Stmt\Finally_; usePhpParser\Node\Stmt\TryCatch; $echo = newEcho_([newString_('one')]); $tryStmts = [$echo]; $echo2 = newEcho_([newString_('two')]); $catch = newCatch_([newFullyQualified('SomeType')], null, [$echo2]); $echo3 = newEcho_([newString_('three')]); $finally = newFinally_([$echo3]); returnnewTryCatch($tryStmts, [$catch]);
↓
try { echo'one'; } catch (\SomeType) { echo'two'; }
$stmts
-/** @var Node\Stmt[] Statements */
$catches
-/** @var Catch_[] Catches */
$finally
-/** @var null|Finally_ Optional finally node */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Variable; usePhpParser\Node\Stmt\Unset_; $variable = newVariable('variableName'); returnnewUnset_([$variable]);
↓
unset($variableName);
$vars
-/** @var Node\Expr[] Variables to unset */
<?phpdeclare(strict_types=1); usePhpParser\Node\Name; usePhpParser\Node\Stmt\Use_; usePhpParser\Node\Stmt\UseUse; $useUse = newUseUse(newName('UsedNamespace')); returnnewUse_([$useUse]);
↓
useUsedNamespace;
$type
-/** @var int Type of alias */
$uses
-/** @var UseUse[] Aliases */
<?phpdeclare(strict_types=1); usePhpParser\Node\Expr\Variable; usePhpParser\Node\Stmt\While_; returnnewWhile_(newVariable('variableName'));
↓
while ($variableName) { }
$cond
-/** @var Node\Expr Condition */
$stmts
-/** @var Node\Stmt[] Statements */
<?phpdeclare(strict_types=1); usePhpParser\Node\Identifier; usePhpParser\Node\UnionType; $unionedTypes = [newIdentifier('string'), newIdentifier('int')]; returnnewUnionType($unionedTypes);
↓
string|int
$types
-/** @var (Identifier|Name|IntersectionType)[] Types */