{"record":{"id":"a77be2fb243b188d","repo":"twigphp/Twig","slug":"using-s-for-the-value-of-node-s-of-s-is-not-supported-you","errorCode":null,"errorMessage":"Using \"%s\" for the value of node \"%s\" of \"%s\" is not supported. You must pass a \\Twig\\Node\\Node instance.","messagePattern":"Using \"(.+?)\" for the value of node \"(.+?)\" of \"(.+?)\" is not supported\\. You must pass a \\\\Twig\\\\Node\\\\Node instance\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Node/Node.php","lineNumber":57,"sourceCode":"    /** @var array<string, NameDeprecation> */\n    private $nodeNameDeprecations = [];\n    /** @var array<string, NameDeprecation> */\n    private $attributeNameDeprecations = [];\n\n    /**\n     * @param array<string|int, Node> $nodes      An array of named nodes\n     * @param array                   $attributes An array of attributes (should not be nodes)\n     * @param int                     $lineno     The line number\n     */\n    public function __construct(array $nodes = [], array $attributes = [], int $lineno = 0)\n    {\n        if (self::class === static::class) {\n            trigger_deprecation('twig/twig', '3.15', \\sprintf('Instantiating \"%s\" directly is deprecated; the class will become abstract in 4.0.', self::class));\n        }\n\n        foreach ($nodes as $name => $node) {\n            if (!$node instanceof self) {\n                throw new \\InvalidArgumentException(\\sprintf('Using \"%s\" for the value of node \"%s\" of \"%s\" is not supported. You must pass a \\Twig\\Node\\Node instance.', get_debug_type($node), $name, static::class));\n            }\n        }\n        $this->nodes = $nodes;\n        $this->attributes = $attributes;\n        $this->lineno = $lineno;\n\n        if (\\func_num_args() > 3) {\n            trigger_deprecation('twig/twig', '3.12', \\sprintf('The \"tag\" constructor argument of the \"%s\" class is deprecated and ignored (check which TokenParser class set it to \"%s\"), the tag is now automatically set by the Parser when needed.', static::class, func_get_arg(3) ?: 'null'));\n        }\n    }\n\n    public function __toString(): string\n    {\n        $repr = static::class;\n\n        if ($this->tag) {\n            $repr .= \\sprintf(\"\\n  tag: %s\", $this->tag);\n        }","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Node/Node.php#L39-L75","documentation":"The base Node constructor validates that every child in the $nodes map is itself a Node instance; passing anything else (string, array, scalar) is rejected with an InvalidArgumentException. Twig's AST is strictly tree-structured, and the compiler relies on every child being a Node.","triggerScenarios":"Constructing any Node subclass (or Node itself, which is deprecated since 3.15) with a children array containing non-Node values, e.g. `new MyNode(['name' => 'text'])` instead of `new TextNode('text')`.","commonSituations":"Hand-writing custom Twig nodes/extensions; passing attributes (which belong in the $attributes argument) into the $nodes argument by mistake; instantiating Node directly after the 3.15 deprecation.","solutions":["Wrap raw values in the appropriate Node subclass (TextNode, ConstantExpression, etc.) before passing them in $nodes.","Move non-node data (strings, flags, config) into the $attributes constructor argument instead of $nodes.","Check get_debug_type($node) at the failing key to locate the offending entry."],"exampleFix":"// before\nnew \\Twig\\Node\\Node(['msg' => 'hello']);\n// after\nnew \\Twig\\Node\\Node(['msg' => new \\Twig\\Node\\TextNode('hello')]);","handlingStrategy":"type-guard","validationCode":"foreach ($nodes as $name => $n) {\n    if (!$n instanceof \\Twig\\Node\\Node) throw new InvalidArgumentException(\"Child '$name' must be a Node\");\n}","typeGuard":"function isNodeMap(array $nodes): bool { foreach ($nodes as $n) { if (!$n instanceof \\Twig\\Node\\Node) return false; } return true; }","tryCatchPattern":"try {\n    $node = new MyNode($children, $attributes);\n} catch (\\InvalidArgumentException $e) {\n    // a child was not a Node; wrap raw values before constructing\n}","preventionTips":["Remember $nodes takes Node children; scalars go in $attributes","Wrap raw values in TextNode/ConstantExpression before passing","Avoid instantiating Node directly (deprecated since Twig 3.15, abstract in 4.0)"],"tags":["twig","ast","node"],"backgroundTag":"type-mismatch","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}