{"record":{"id":"6b944ce80393de4c","repo":"composer/composer","slug":"invalid-value-for-name-value-expected-0-1","errorCode":null,"errorMessage":"Invalid value for {$name}: {$value}. Expected 0, 1, false, true, off, or on.","messagePattern":"Invalid value for (.+?): (.+?)\\. Expected 0, 1, false, true, off, or on\\.","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Composer/Util/Platform.php","lineNumber":106,"sourceCode":"\n    /**\n     * Read a boolean-style env var. Accepts only the literal strings '0' or '1'.\n     *\n     * Returns true for '1', false for '0', and $default when the variable is unset.\n     * Throws \\RuntimeException for any other value (including the empty string).\n     *\n     * @param non-empty-string $name\n     * @return ($default is bool ? bool : ?bool)\n     */\n    public static function getBoolEnv(string $name, ?bool $default = null): ?bool\n    {\n        $value = self::getEnv($name);\n        if (false === $value || '' === $value) {\n            return $default;\n        }\n\n        if (!in_array($value, ['0', '1', 'false', 'true', 'off', 'on'], true)) {\n            throw new \\RuntimeException(\n                \"Invalid value for {$name}: {$value}. Expected 0, 1, false, true, off, or on.\"\n            );\n        }\n\n        return in_array($value, ['1', 'true', 'on', ], true);\n    }\n\n    /**\n     * Refuses to parse a tar/phar archive on PHP < 8.0, where the \\Phar/\\PharData\n     * constructor handles archive metadata in a way that is unsafe with untrusted\n     * input. PHP 8.0+ is not affected, so this is a no-op there.\n     *\n     * @internal\n     * @throws \\RuntimeException when run on PHP < 8.0 without the explicit opt-out env var\n     */\n    public static function assertPharMetadataSafe(): void\n    {\n        if (\\PHP_VERSION_ID >= 80000) {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/composer/composer/blob/6ffc1177404d0c50119c22dde6564a380f4a82c9/src/Composer/Util/Platform.php#L88-L124","documentation":"Thrown by Platform::getBoolEnv() when an environment variable is set but its value is not one of the strict literals '0', '1', 'false', 'true', 'off', 'on'. The method deliberately rejects fuzzy booleans (yes/no, TRUE with whitespace, 2, quoted values) so config behavior is deterministic. An unset or empty variable does NOT trigger this — it returns the default.","triggerScenarios":"Calling Platform::getBoolEnv('SOME_VAR') (or any Composer code path that reads a bool env var such as COMPOSER_NO_INTERACTION, COMPOSER_DISABLE_NETWORK, etc.) where SOME_VAR is exported with a value like 'yes', 'no', '2', 'TRUE', ' true ', or 'enable'. The check is case- and whitespace-sensitive.","commonSituations":"CI config (GitLab/GitHub Actions env:) sets COMPOSER_* flags to 'true' with surrounding quotes or to yes/no; a .env file uses ON/OFF variants the shell leaves verbatim; a Docker ENV statement copies a value with trailing whitespace; migrating from another tool that accepted 'yes'/'no'.","solutions":["Set the variable to a literal '1' or '0' (preferred): e.g. export SOME_VAR=1","If the flag should be off, unset the variable entirely rather than setting it to 'no'/'off-but-different'","Trim whitespace and lowercase the value in your shell wrapper before exporting: export SOME_VAR=$(echo \"$SOME_VAR\" | tr '[:upper:]' '[:lower:]' | xargs)","Audit all COMPOSER_* and library-specific bool vars in your env for values outside the allowed set"],"exampleFix":"// before\nexport COMPOSER_DISABLE_NETWORK=yes   # triggers the error\n\n// after\nexport COMPOSER_DISABLE_NETWORK=1      # accepted literal","handlingStrategy":"validation","validationCode":"// Validate/normalize the env var BEFORE relying on Platform::getBoolEnv\n$raw = getenv('SOME_VAR');\nif ($raw !== false && $raw !== '') {\n    $normalized = strtolower(trim($raw));\n    if (!in_array($normalized, ['0','1','false','true','off','on'], true)) {\n        throw new \\InvalidArgumentException(\n            \"SOME_VAR must be one of 0/1/false/true/off/on, got: {$raw}\"\n        );\n    }\n}\n// now safe to call\n$flag = Platform::getBoolEnv('SOME_VAR', false);","typeGuard":null,"tryCatchPattern":"// Wrap reads of bool env vars so a bad value degrades gracefully\ntry {\n    $flag = Platform::getBoolEnv('SOME_VAR', false);\n} catch (\\RuntimeException $e) {\n    // log and fall back to default rather than aborting\n    error_log($e->getMessage());\n    $flag = false;\n}","preventionTips":["Document the accepted literals (0/1/false/true/off/on) next to every bool env var you expose","Normalize env values (trim + lowercase) in a single shell entrypoint before PHP starts","Add a startup check that asserts all known bool vars are in the allowed set","Never use yes/no/yes-strings for boolean config that Composer will read"],"tags":["environment","config","validation","php"],"analyzedSha":"6ffc1177404d0c50119c22dde6564a380f4a82c9","analyzedAt":"2026-08-07T00:01:08.491Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}