{"record":{"id":"5b8725763bd2bab7","repo":"symfony/http-kernel","slug":"argument-s-does-not-have-a-default-value-use-s","errorCode":null,"errorMessage":"Argument $%s does not have a default value. Use \"%s::hasDefaultValue()\" to avoid this exception.","messagePattern":"Argument \\$(.+?) does not have a default value\\. Use \"(.+?)::hasDefaultValue\\(\\)\" to avoid this exception\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"ControllerMetadata/ArgumentMetadata.php","lineNumber":89,"sourceCode":"    }\n\n    /**\n     * Returns whether the argument accepts null values.\n     */\n    public function isNullable(): bool\n    {\n        return $this->isNullable;\n    }\n\n    /**\n     * Returns the default value of the argument.\n     *\n     * @throws \\LogicException if no default value is present; {@see self::hasDefaultValue()}\n     */\n    public function getDefaultValue(): mixed\n    {\n        if (!$this->hasDefaultValue) {\n            throw new \\LogicException(\\sprintf('Argument $%s does not have a default value. Use \"%s::hasDefaultValue()\" to avoid this exception.', $this->name, __CLASS__));\n        }\n\n        return $this->defaultValue;\n    }\n\n    /**\n     * @param class-string          $name\n     * @param self::IS_INSTANCEOF|0 $flags\n     *\n     * @return array<object>\n     */\n    public function getAttributes(?string $name = null, int $flags = 0): array\n    {\n        if (!$name) {\n            return $this->attributes;\n        }\n\n        return $this->getAttributesOfType($name, $flags);","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/ControllerMetadata/ArgumentMetadata.php#L71-L107","documentation":"ArgumentMetadata::getDefaultValue() throws LogicException when the underlying controller/function argument has no default value. Symfony's argument metadata exposes hasDefaultValue() for checking first; calling getDefaultValue() on a required argument is a programmer error guarded by that exception.","triggerScenarios":"Calling getDefaultValue() on an ArgumentMetadata built from a parameter without a default (e.g. a route placeholder like {id} with no default in the action signature); argument resolvers or profiler code that skip the hasDefaultValue() check.","commonSituations":"Custom ArgumentValueResolver code reading default values for all arguments; debugging tools/profilers introspecting controller signatures; Symfony version change where getDefaultValue()'s contract became stricter (exception documented with @throws).","solutions":["Call hasDefaultValue() first and only call getDefaultValue() when it returns true.","For required arguments, treat the absence of a default as expected logic (no value available) rather than an error to unwrap.","If you control the signature, add an explicit default (e.g. int $id = 0) if a default actually makes sense."],"exampleFix":"// before\n$default = $argument->getDefaultValue();\n// after\n$default = $argument->hasDefaultValue() ? $argument->getDefaultValue() : null;","handlingStrategy":"type-guard","validationCode":"if (!$argument->hasDefaultValue()) {\n    return null; // or handle required argument explicitly\n}","typeGuard":"function safeDefaultValue(\\Symfony\\Component\\HttpKernel\\ControllerMetadata\\ArgumentMetadata $arg): mixed\n{\n    return $arg->hasDefaultValue() ? $arg->getDefaultValue() : null;\n}","tryCatchPattern":"try {\n    $default = $argument->getDefaultValue();\n} catch (\\LogicException $e) {\n    $default = null; // argument is required, no default exists\n}","preventionTips":["Always pair getDefaultValue() with hasDefaultValue() — the API contract requires it.","Use IDE doc @throws hints to spot guarded accessors before calling them.","In custom argument resolvers, branch on hasDefaultValue() before reading defaults.","When writing reflection-based tooling, rely on ReflectionParameter::isDefaultValueAvailable() upstream too."],"tags":["symfony","argument-metadata","logic-exception","introspection"],"backgroundTag":"internal-invariant-violation","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}