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

  1. Fix or remove the unknown argument named in the message; the accepted parameters are listed in the error.
  2. Check the callable's signature after any dependency upgrade — parameters may have been renamed.
  3. 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

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


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): string

View on GitHub (pinned to a414c3a491)