{"record":{"id":"80c4e2e88a4e81f1","repo":"twigphp/Twig","slug":"positional-arguments-cannot-be-used-after-named-arguments","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/Node/Expression/CallExpression.php","lineNumber":158,"sourceCode":"\n    /**\n     * @deprecated since Twig 3.12, use Twig\\Util\\CallableArgumentsExtractor::getArguments() instead\n     */\n    protected function getArguments($callable, $arguments)\n    {\n        trigger_deprecation('twig/twig', '3.12', 'The \"%s()\" method is deprecated, use Twig\\Util\\CallableArgumentsExtractor::getArguments() instead.', __METHOD__);\n\n        $callType = $this->getAttribute('type');\n        $callName = $this->getAttribute('name');\n\n        $parameters = [];\n        $named = false;\n        foreach ($arguments as $name => $node) {\n            if (!\\is_int($name)) {\n                $named = true;\n                $name = $this->normalizeName($name);\n            } elseif ($named) {\n                throw new SyntaxError(\\sprintf('Positional arguments cannot be used after named arguments for %s \"%s\".', $callType, $callName), $this->getTemplateLine(), $this->getSourceContext());\n            }\n\n            $parameters[$name] = $node;\n        }\n\n        $isVariadic = $this->getAttribute('twig_callable')->isVariadic();\n        if (!$named && !$isVariadic) {\n            return $parameters;\n        }\n\n        if (!$callable) {\n            if ($named) {\n                $message = \\sprintf('Named arguments are not supported for %s \"%s\".', $callType, $callName);\n            } else {\n                $message = \\sprintf('Arbitrary positional arguments are not supported for %s \"%s\".', $callType, $callName);\n            }\n\n            throw new \\LogicException($message);","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Node/Expression/CallExpression.php#L140-L176","documentation":"When Twig compiles a function/filter call, getArguments collects arguments in order. Once a named argument is seen, all subsequent positional arguments are ambiguous because they can no longer map to their natural positions, so a SyntaxError is thrown naming the callable type and name.","triggerScenarios":"Templates like `{{ range(start=1, 10) }}` or `{{ 'x'|filter(arr, fn, foo=1) }}` — a named argument followed by an integer-keyed (positional) argument; also direct PHP construction of a CallExpression with arguments passed in that mixed order.","commonSituations":"Incrementally converting calls to named arguments and missing one positional leftover; copy-pasted snippets mixing both styles; macros/functions with many parameters where the author switched styles mid-call.","solutions":["Move the positional arguments before any named arguments: `{{ range(1, 10) }}` or `{{ range(1, end=10) }}`.","Convert ALL arguments after the first named one to named form: `{{ range(start=1, end=10) }}`.","Check the callable's signature to get the correct parameter names before mixing styles."],"exampleFix":"// before (template)\n{{ range(start=1, 10) }}\n// after\n{{ range(1, 10) }}","handlingStrategy":"validation","validationCode":"// Keep positional arguments contiguous at the start of a call.\n// Bad:  foo(a=1, 2)\n// Good: foo(2, a=1)  or  foo(a=1, b=2)\n$call = 'range(start=1, 10)';\nif (preg_match('/\\w+\\s*=\\s*[^,]+,\\s*[^\\w=)}]/', $call)) {\n    // suspicious mixed order — rewrite the call before rendering\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Adopt one style per call: all positional, or positional-first then all named.","When converting a call to named arguments, convert every argument in that call.","Look up the function/filter signature to confirm parameter names before using named arguments."],"tags":["twig","arguments","syntax-error","template-compilation"],"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"}