{"record":{"id":"cfa19f59ac02c1b6","repo":"twigphp/Twig","slug":"value-for-argument-s-is-required-for-s-s-cfa19f","errorCode":null,"errorMessage":"Value for argument \"%s\" is required for %s \"%s\".","messagePattern":"Value for argument \"(.+?)\" is required for (.+?) \"(.+?)\"\\.","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"src/Util/CallableArgumentsExtractor.php","lineNumber":61,"sourceCode":"        $extractedArgumentNameMap = [];\n        $named = false;\n        foreach ($arguments as $name => $node) {\n            if (!\\is_int($name)) {\n                $named = true;\n            } elseif ($named) {\n                throw new SyntaxError(\\sprintf('Positional arguments cannot be used after named arguments for %s \"%s\".', $this->twigCallable->getType(), $this->twigCallable->getName()), $this->node->getTemplateLine(), $this->node->getSourceContext());\n            }\n\n            $extractedArguments[$normalizedName = $this->normalizeName($name)] = $node;\n            $extractedArgumentNameMap[$normalizedName] = $name;\n        }\n\n        if (!$named && !$this->twigCallable->isVariadic()) {\n            $min = $this->twigCallable->getMinimalNumberOfRequiredArguments();\n            if (\\count($extractedArguments) < $this->rc->getReflector()->getNumberOfRequiredParameters() - $min) {\n                $argName = $this->toSnakeCase($this->rc->getReflector()->getParameters()[$min + \\count($extractedArguments)]->getName());\n\n                throw new SyntaxError(\\sprintf('Value for argument \"%s\" is required for %s \"%s\".', $argName, $this->twigCallable->getType(), $this->twigCallable->getName()), $this->node->getTemplateLine(), $this->node->getSourceContext());\n            }\n\n            return $extractedArguments;\n        }\n\n        if (!$callable = $this->twigCallable->getCallable()) {\n            if ($named) {\n                throw new SyntaxError(\\sprintf('Named arguments are not supported for %s \"%s\".', $this->twigCallable->getType(), $this->twigCallable->getName()));\n            }\n\n            throw new SyntaxError(\\sprintf('Arbitrary positional arguments are not supported for %s \"%s\".', $this->twigCallable->getType(), $this->twigCallable->getName()));\n        }\n\n        [$callableParameters, $isPhpVariadic] = $this->getCallableParameters();\n        $arguments = [];\n        $callableParameterNames = [];\n        $missingArguments = [];\n        $optionalArguments = [];","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Util/CallableArgumentsExtractor.php#L43-L79","documentation":"For non-variadic callables with no named arguments, extractArguments() checks that the number of supplied arguments covers the required parameters of the underlying PHP callable (offset by hidden internal required arguments). When too few arguments are given, it throws a SyntaxError naming the first missing required argument, the callable type, and its name.","triggerScenarios":"A template calls a Twig function/filter/test with fewer positional arguments than the mapped PHP callable requires, e.g. {{ max() }} or {{ range(1) }} when the callable demands more parameters.","commonSituations":"Typos or refactorings that drop an argument; custom Twig extensions exposing PHP functions whose required arity exceeds what templates pass; upgrading an extension where a parameter gained a required argument.","solutions":["Supply the missing required argument named in the message at the indicated position.","Give the missing argument a default value in the underlying PHP callable if it is genuinely optional.","Check the extension's registered callable signature and update the template call to match it."],"exampleFix":"{# before #}\n{{ range(5) }}\n{# after (if start is required) #}\n{{ range(0, 5) }}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return $twig->render($name, $ctx);\n} catch (Twig\\Error\\SyntaxError $e) {\n    if (preg_match('/Value for argument \"(.+?)\" is required/', $e->getMessage(), $m)) {\n        throw new DomainException('Template call missing required argument \"'.$m[1].'\" at line '.$e->getTemplateLine(), 0, $e);\n    }\n    throw $e;\n}","preventionTips":["Check each custom Twig callable's signature against all template call sites when adding required parameters.","Add default values to parameters that are genuinely optional.","Lint templates in CI so missing-argument mistakes fail before deployment."],"tags":["twig","missing-argument","compile-time","syntax-error"],"backgroundTag":"missing-required-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"}