twigphp/Twig · error · SyntaxError
Unknown argument " " for " ( )".
Error message
Unknown argument%s "%s" for %s "%s(%s)".
What it means
After mapping all supplied arguments onto the callable's known parameters, extractArguments() throws this SyntaxError for leftover arguments that match no parameter — listing all unknown argument names, the callable's type, name, and its accepted parameter list. Pluralization and the offending argument's line are computed for a precise compile-time message.
Solutions
- Fix or remove the unknown argument named in the message; the accepted parameters are listed in the error.
- Check the callable's signature after any dependency upgrade — parameters may have been renamed.
- If the callable should accept the option, add the corresponding parameter to the extension's callable.
Example fix
{# before #}
{{ 'x'|upper(strict=true) }}
{# after: upper takes no options #}
{{ 'x'|upper }} Defensive patterns
Strategy: try-catch
Try / catch
try {
$out = $twig->render($template, $ctx);
} catch (Twig\Error\SyntaxError $e) {
if (preg_match('/Unknown arguments? "([^"]+)" for/', $e->getMessage(), $m)) {
error_log('Unknown option "'.$m[1].'" at line '.$e->getTemplateLine().' — check accepted parameters in the message');
}
throw $e;
} Prevention
- Copy argument names from the callable's documented signature; watch for typos and casing.
- After upgrading libraries, grep templates for options of changed callables and verify against new signatures.
- Use bin/console lint:twig (or twig linter) in CI so unknown arguments fail the build, not production.
When it happens
Trigger: Passing a named argument that does not match (after normalization) any parameter of the function/filter/test, e.g. {{ date(timezone='UTC') }} on a callable with no $timezone parameter, or an unknown filter option.
Common situations: Typo'd option names (case or underscore variants that don't normalize); upgrading a library where a callable's parameters were renamed or removed; mixing up similarly named functions with different signatures.
Related errors
- Calling the "parent" function outside of a block is…
- Calling the "parent" function on a template that does not…
- You cannot assign a value to
- A template that extends another one cannot include content…
- Positional arguments cannot be used after named arguments…
AI-assisted analysis of twigphp/Twig@a414c3a491 (2026-09-13).
Data as JSON: /api/errors/eda0f83bd0435202.
Report an issue: GitHub.
Appendix: source
Thrown at src/Util/CallableArgumentsExtractor.php:161
unset($extractedArguments[$key]);
}
if ($arbitraryArguments->count()) {
$arguments = array_merge($arguments, $optionalArguments);
$arguments[] = $arbitraryArguments;
}
}
if ($extractedArguments) {
$unknownArgument = null;
foreach ($extractedArguments as $extractedArgument) {
if ($extractedArgument instanceof Node) {
$unknownArgument = $extractedArgument;
break;
}
}
throw new SyntaxError(
\sprintf(
'Unknown argument%s "%s" for %s "%s(%s)".',
\count($extractedArguments) > 1 ? 's' : '', implode('", "', array_keys($extractedArguments)), $this->twigCallable->getType(), $this->twigCallable->getName(), implode(', ', array_map([$this, 'toSnakeCase'], $callableParameterNames))
),
$unknownArgument ? $unknownArgument->getTemplateLine() : $this->node->getTemplateLine(),
$unknownArgument ? $unknownArgument->getSourceContext() : $this->node->getSourceContext()
);
}
return $arguments;
}
private function normalizeName(string $name): string
{
return strtolower(str_replace('_', '', $name));
}
private function toSnakeCase(string $name): stringView on GitHub (pinned to a414c3a491)