{"record":{"id":"c899e041684a7885","repo":"twigphp/Twig","slug":"named-arguments-are-not-supported-for-s-s-arbitrary","errorCode":null,"errorMessage":"Named arguments are not supported for %s \"%s\". / Arbitrary positional arguments are not supported for %s \"%s\".","messagePattern":"Named arguments are not supported for (.+?) \"(.+?)\"\\. / Arbitrary positional arguments are not supported for (.+?) \"(.+?)\"\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"src/Node/Expression/CallExpression.php","lineNumber":176,"sourceCode":"                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);\n        }\n\n        [$callableParameters, $isPhpVariadic] = $this->getCallableParameters($callable, $isVariadic);\n        $arguments = [];\n        $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","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Node/Expression/CallExpression.php#L158-L194","documentation":"Twig throws this LogicException when a callable (filter, function, test) is invoked with named or arbitrary positional (spread) arguments, but the underlying PHP callable's signature does not declare support for them. Twig inspects the callable's reflection to decide which argument-passing styles are allowed, and rejects calls that cannot be mapped onto real parameters.","triggerScenarios":"Calling a Twig filter/function/test with named arguments (e.g. `my_filter(foo: 1)`) when the PHP function has no matching named parameter, or using argument spreading (e.g. `f(...arr)`), from getArguments() while compiling CallExpression.","commonSituations":"Upgrading Twig templates that previously relied on positional-only behavior; exposing a custom filter/function whose PHP signature lacks named/variadic parameters; typos in named argument names that Twig cannot bind.","solutions":["Declare proper named/typed parameters on the PHP callable, e.g. `function my_filter($value, string $foo = '')` so named arguments can be mapped.","Change the template call to positional arguments matching the callable's parameter order.","If the callable should accept arbitrary arguments, add a variadic parameter (`...$args`) and mark the Twig callable as variadic (is_variadic option)."],"exampleFix":"// before\n$twig->addFunction(new \\Twig\\TwigFunction('sum', function (...$args) { /* variadic unsupported */ }));\n// after\n$twig->addFunction(new \\Twig\\TwigFunction('sum', function (...$args) { return array_sum($args); }, ['is_variadic' => true]));","handlingStrategy":"validation","validationCode":"// Before rendering, ensure named args map to real parameters:\n$r = new ReflectionFunction('my_filter');\nforeach ($namedArgs as $name => $v) {\n    if (!$r->getParameters() || !in_array($name, array_map(fn($p) => $p->getName(), $r->getParameters()), true)) {\n        throw new InvalidArgumentException(\"Unknown named argument: $name\");\n    }\n}","typeGuard":"function supportsNamedArgs(callable $c): bool {\n    $r = is_array($c) ? new ReflectionMethod($c[0], $c[1]) : new ReflectionFunction($c);\n    foreach ($r->getParameters() as $p) { if (!$p->isVariadic() && $p->isOptional()) return true; }\n    return false;\n}","tryCatchPattern":null,"preventionTips":["Declare typed, named parameters in custom filters/functions/tests","Use 'is_variadic' => true when the callable takes ...$args","Prefer positional arguments in templates unless named args are explicitly supported"],"tags":["twig","template","arguments"],"backgroundTag":"invalid-argument","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"}