{"record":{"id":"457aa21dd551e1ac","repo":"twigphp/Twig","slug":"positional-arguments-cannot-be-used-after-named-arguments-457aa2","errorCode":null,"errorMessage":"Positional arguments cannot be used after named arguments for %s \"%s\".","messagePattern":"Positional arguments cannot be used after named arguments for (.+?) \"(.+?)\"\\.","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"src/Util/CallableArgumentsExtractor.php","lineNumber":49,"sourceCode":"        private Node $node,\n        private TwigCallableInterface $twigCallable,\n    ) {\n        $this->rc = new ReflectionCallable($twigCallable);\n    }\n\n    /**\n     * @return array<Node>\n     */\n    public function extractArguments(Node $arguments): array\n    {\n        $extractedArguments = [];\n        $extractedArgumentNameMap = [];\n        $named = false;\n        foreach ($arguments as $name => $node) {\n            if (!\\is_int($name)) {\n                $named = true;\n            } elseif ($named) {\n                throw new SyntaxError(\\sprintf('Positional arguments cannot be used after named arguments for %s \"%s\".', $this->twigCallable->getType(), $this->twigCallable->getName()), $this->node->getTemplateLine(), $this->node->getSourceContext());\n            }\n\n            $extractedArguments[$normalizedName = $this->normalizeName($name)] = $node;\n            $extractedArgumentNameMap[$normalizedName] = $name;\n        }\n\n        if (!$named && !$this->twigCallable->isVariadic()) {\n            $min = $this->twigCallable->getMinimalNumberOfRequiredArguments();\n            if (\\count($extractedArguments) < $this->rc->getReflector()->getNumberOfRequiredParameters() - $min) {\n                $argName = $this->toSnakeCase($this->rc->getReflector()->getParameters()[$min + \\count($extractedArguments)]->getName());\n\n                throw new SyntaxError(\\sprintf('Value for argument \"%s\" is required for %s \"%s\".', $argName, $this->twigCallable->getType(), $this->twigCallable->getName()), $this->node->getTemplateLine(), $this->node->getSourceContext());\n            }\n\n            return $extractedArguments;\n        }\n\n        if (!$callable = $this->twigCallable->getCallable()) {","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Util/CallableArgumentsExtractor.php#L31-L67","documentation":"During template compilation, CallableArgumentsExtractor::extractArguments() validates the argument order of calls to Twig functions, filters, and tests. If a positional argument appears after a named one, a SyntaxError is thrown because PHP cannot bind arguments that way and Twig cannot map them deterministically. The error is raised at compile time with the offending template line.","triggerScenarios":"A template calls a function/filter/test (e.g. {{ date(format='Y', 'now') }}) with an integer-keyed argument following a string-keyed (named) argument in the node's argument list.","commonSituations":"Adding a named option in the middle of an existing positional call; code-generated templates that append named options before remaining positional values; copy-pasted calls reordered by hand.","solutions":["Reorder the call so positional arguments precede named arguments.","Give the positional argument its name so the entire call is named-argument based.","If the callable supports it, check the documented signature for the correct parameter order."],"exampleFix":"{# before #}\n{{ date(format='Y-m-d', 'now') }}\n{# after #}\n{{ date('now', format='Y-m-d') }}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    $template->render($context);\n} catch (Twig\\Error\\SyntaxError $e) {\n    if (str_contains($e->getMessage(), 'Positional arguments cannot be used after named arguments')) {\n        // point CI/dev at $e->getTemplateLine() in $e->getSourceContext()->getName()\n        log($e->getMessage().' in '.$e->getSourceContext()->getName().' line '.$e->getTemplateLine());\n    }\n    throw $e;\n}","preventionTips":["Keep positional arguments first in every function/filter/test call.","Enable Twig linting (bin/console lint:twig) in CI to catch argument-order mistakes at build time.","Code-review any call where a named option was inserted mid-call."],"tags":["twig","syntax-error","arguments","compile-time"],"backgroundTag":"invalid-argument-order","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"}