{"record":{"id":"df8002ff563dd928","repo":"symfony/http-foundation","slug":"parameter-value-s-cannot-be-converted-to-bool","errorCode":null,"errorMessage":"Parameter value \"%s\" cannot be converted to \"bool\".","messagePattern":"Parameter value \"(.+?)\" cannot be converted to \"bool\"\\.","errorType":"exception","errorClass":"UnexpectedValueException","httpStatus":null,"severity":"error","filePath":"ParameterBag.php","lineNumber":176,"sourceCode":"\n    /**\n     * Returns the parameter value converted to integer.\n     *\n     * @throws UnexpectedValueException if the value cannot be converted to integer\n     */\n    public function getInt(string $key, int $default = 0): int\n    {\n        return $this->filter($key, $default, \\FILTER_VALIDATE_INT, ['flags' => \\FILTER_REQUIRE_SCALAR | \\FILTER_NULL_ON_FAILURE]) ?? throw new UnexpectedValueException(\\sprintf('Parameter value \"%s\" cannot be converted to \"int\".', $key));\n    }\n\n    /**\n     * Returns the parameter value converted to boolean.\n     *\n     * @throws UnexpectedValueException if the value cannot be converted to a boolean\n     */\n    public function getBoolean(string $key, bool $default = false): bool\n    {\n        return $this->filter($key, $default, \\FILTER_VALIDATE_BOOL, ['flags' => \\FILTER_REQUIRE_SCALAR | \\FILTER_NULL_ON_FAILURE]) ?? throw new UnexpectedValueException(\\sprintf('Parameter value \"%s\" cannot be converted to \"bool\".', $key));\n    }\n\n    /**\n     * Returns the parameter value converted to an enum.\n     *\n     * @template T of \\BackedEnum\n     *\n     * @param class-string<T> $class\n     * @param ?T              $default\n     *\n     * @return ?T\n     *\n     * @psalm-return ($default is null ? T|null : T)\n     *\n     * @throws UnexpectedValueException if the parameter value cannot be converted to an enum\n     */\n    public function getEnum(string $key, string $class, ?\\BackedEnum $default = null): ?\\BackedEnum\n    {","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/symfony/http-foundation/blob/5aea19cd678fa4140f6108406f1096de5e9ed6e4/ParameterBag.php#L158-L194","documentation":"ParameterBag::getBoolean() converts a stored parameter to a bool using PHP's FILTER_VALIDATE_BOOL with FILTER_NULL_ON_FAILURE. If the filter cannot interpret the value as a boolean (it returns null), the method throws UnexpectedValueException with the parameter's key in the message. This guards callers from silently getting a wrong default for genuinely invalid stored values.","triggerScenarios":"Calling $bag->getBoolean('key') when the stored value is a non-boolean non-coercible string like 'yes-not', 'on/off' misspellings, an array, or an object. Only '1','0','true','false','on','off','yes','no' (case-insensitive) convert.","commonSituations":"Config values read from env vars or YAML/JSON where 'True', 'enabled', or integers other than 0/1 are stored; a parameter accidentally set to an array.","solutions":["Store only canonical boolean strings ('true'/'false', '1'/'0', 'on'/'off', 'yes'/'no') in the parameter bag","Read the value and convert manually with a filter_var($bag->get('key'), FILTER_VALIDATE_BOOL) plus your own fallback","Catch UnexpectedValueException and apply an application-level default","Fix the config source (env var, yaml file) that supplied the bad value"],"exampleFix":"// before\n$debug = $bag->getBoolean('debug'); // throws if 'debug' => 'enabled'\n// after\n$debug = filter_var($bag->get('debug'), \\FILTER_VALIDATE_BOOL, ['flags' => \\FILTER_NULL_ON_FAILURE]) ?? false;","handlingStrategy":"try-catch","validationCode":"$v = $bag->has($key) ? $bag->get($key) : null;\nif (null !== $v && !is_bool($v) && !in_array(strtolower((string) $v), ['1','0','true','false','on','off','yes','no'], true)) {\n    throw new \\InvalidArgumentException(\"$key is not a boolean: \".get_debug_type($v));\n}","typeGuard":"function isBoolLike(mixed $v): bool {\n    return is_bool($v) || in_array(strtolower((string) $v), ['1','0','true','false','on','off','yes','no'], true);\n}","tryCatchPattern":"try {\n    $flag = $bag->getBoolean('key');\n} catch (\\UnexpectedValueException $e) {\n    $flag = false; // or log + default\n}","preventionTips":["Store only canonical boolean strings/ints in parameter bags","Use getBoolean's $default parameter for optional flags","Validate env/config values at boot with a config validator","Never store arrays or objects under keys read with getBoolean"],"tags":["parameters","boolean","configuration","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"5aea19cd678fa4140f6108406f1096de5e9ed6e4","analyzedAt":"2026-09-13T01:52:22.855Z","contentChangedAt":"2026-09-13T01:52:22.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}