{"record":{"id":"7908c3d6ade1752f","repo":"twigphp/Twig","slug":"argument-s-is-defined-twice-for-s-s","errorCode":null,"errorMessage":"Argument \"%s\" is defined twice for %s \"%s\".","messagePattern":"Argument \"(.+?)\" is defined twice for (.+?) \"(.+?)\"\\.","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"src/Node/Expression/CallExpression.php","lineNumber":199,"sourceCode":"        $names = [];\n        $missingArguments = [];\n        $optionalArguments = [];\n        $pos = 0;\n        foreach ($callableParameters as $callableParameter) {\n            $name = $this->normalizeName($callableParameter->name);\n            if (\\PHP_VERSION_ID >= 80000 && 'range' === $callable) {\n                if ('start' === $name) {\n                    $name = 'low';\n                } elseif ('end' === $name) {\n                    $name = 'high';\n                }\n            }\n\n            $names[] = $name;\n\n            if (\\array_key_exists($name, $parameters)) {\n                if (\\array_key_exists($pos, $parameters)) {\n                    throw new SyntaxError(\\sprintf('Argument \"%s\" is defined twice for %s \"%s\".', $name, $callType, $callName), $this->getTemplateLine(), $this->getSourceContext());\n                }\n\n                if (\\count($missingArguments)) {\n                    throw new SyntaxError(\\sprintf(\n                        'Argument \"%s\" could not be assigned for %s \"%s(%s)\" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s \"%s\".',\n                        $name, $callType, $callName, implode(', ', $names), \\count($missingArguments) > 1 ? 's' : '', implode('\", \"', $missingArguments)\n                    ), $this->getTemplateLine(), $this->getSourceContext());\n                }\n\n                $arguments = array_merge($arguments, $optionalArguments);\n                $arguments[] = $parameters[$name];\n                unset($parameters[$name]);\n                $optionalArguments = [];\n            } elseif (\\array_key_exists($pos, $parameters)) {\n                $arguments = array_merge($arguments, $optionalArguments);\n                $arguments[] = $parameters[$pos];\n                unset($parameters[$pos]);\n                $optionalArguments = [];","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Node/Expression/CallExpression.php#L181-L217","documentation":"During compilation of a function/filter/method call, Twig maps named arguments to callable parameters. This error is thrown when the same argument name appears twice in the call's named-argument node, i.e. the template author passed the same named argument more than once (or a name collides with a positional slot already filled). Twig rejects this unconditionally at compile time as a SyntaxError.","triggerScenarios":"A template like {{ date|date(format='d', format='m') }}, or calling a function with a named argument whose name is also claimed by an earlier positional argument, e.g. {{ range(1, low=2) }}. In getArguments(), the name is found in $parameters and its target position $pos is already occupied.","commonSituations":"Copy-pasted argument lists where a parameter was renamed but the old named argument left in place; dynamic templates generated by code that appends named arguments without deduplication; mixing positional and named arguments where a named argument repeats a positional one.","solutions":["Remove the duplicate named argument from the template call","If both values were intended, rename one or combine them","If generating templates programmatically, deduplicate argument names before rendering","Check the exact call signature with twig's debug output or the function's PHP signature to see accepted names"],"exampleFix":"// before (template)\n{{ date(post.created_at, format='Y-m-d', format='d/m/Y') }}\n// after\n{{ date(post.created_at, format='Y-m-d') }}","handlingStrategy":"validation","validationCode":"// Twig (PHP) pre-check before compiling user templates\n$names = [];\nforeach ($node->getNode('arguments') as $key => $arg) {\n    if (\\is_string($key)) {\n        if (isset($names[$key])) { throw new \\RuntimeException(\"Duplicate argument '$key'\"); }\n        $names[$key] = true;\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    $twig->parse($twig->tokenize(new \\Twig\\Source($template, 'index')));\n} catch (\\Twig\\Error\\SyntaxError $e) {\n    if (str_contains($e->getMessage(), 'is defined twice')) {\n        // surface template line: $e->getTemplateLine()\n    }\n}","preventionTips":["Deduplicate named arguments when generating templates programmatically","Never mix a named argument with the same-named positional slot","Lint templates in CI with Twig's parser before deployment"],"tags":["twig","template-compilation","syntax-error","duplicate-argument"],"backgroundTag":"conflicting-config-options","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"}