{"record":{"id":"aa56378997a45dfd","repo":"symfony/polyfill-mbstring","slug":"argument-1-language-must-be-a-valid-language-s-given","errorCode":null,"errorMessage":"Argument #1 ($language) must be a valid language, \"%s\" given","messagePattern":"Argument #1 \\(\\$language\\) must be a valid language, \"(.+?)\" given","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Mbstring.php","lineNumber":436,"sourceCode":"    public static function mb_language($lang = null)\n    {\n        if (null === $lang) {\n            return self::$language;\n        }\n\n        switch ($normalizedLang = strtolower($lang)) {\n            case 'uni':\n            case 'neutral':\n                self::$language = $normalizedLang;\n\n                return true;\n        }\n\n        if (80000 > \\PHP_VERSION_ID) {\n            return false;\n        }\n\n        throw new \\ValueError(\\sprintf('Argument #1 ($language) must be a valid language, \"%s\" given', $lang));\n    }\n\n    public static function mb_list_encodings()\n    {\n        return ['UTF-8'];\n    }\n\n    public static function mb_encoding_aliases($encoding)\n    {\n        switch (strtoupper($encoding)) {\n            case 'UTF8':\n            case 'UTF-8':\n                return ['utf8'];\n        }\n\n        return false;\n    }\n","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/symfony/polyfill-mbstring/blob/d3d318bad5e7a1bfbd026009c8bfb8d8f99ae6b6/Mbstring.php#L418-L454","documentation":"Mbstring::mb_language() throws this ValueError when the requested language name is not recognized. Only a fixed set of languages is accepted, and on PHP >= 8.0 an invalid name throws instead of returning false (pre-8.0 behavior).","triggerScenarios":"Calling mb_language('...') with a $lang that is not null and not one of the supported language names (e.g. a typo like 'en' or 'english' instead of 'English').","commonSituations":"Passing lowercase or free-form language names from config; assuming any BCP-47 tag like 'en-US' is valid; copying code written for a different mbstring version with a different language list.","solutions":["Pass one of the supported language names exactly (e.g. 'uni', 'Japanese', 'English' — check the polyfill's accepted list)","Guard the value against the supported list before calling","Omit the argument or pass null to just read the current language","On PHP < 8 rely on the false return value; on PHP >= 8 catch \\ValueError"],"exampleFix":"// before\nmb_language('en');\n// after\nmb_language('English'); // use an exact supported language name","handlingStrategy":"validation","validationCode":"$supported = ['uni','none','Japanese','ja','English','en','UTF-8','ASCII','EUC-JP','SJIS'];\nif (!in_array($lang, $supported, true)) {\n    $lang = 'uni';\n}\nmb_language($lang);","typeGuard":"function isSupportedLanguage(?string $lang): bool\n{\n    return $lang === null || @mb_language($lang) !== false;\n}","tryCatchPattern":"try {\n    mb_language($lang);\n} catch (\\ValueError $e) {\n    mb_language('uni');\n}","preventionTips":["Use exact supported language names, not arbitrary BCP-47 tags","Normalize case before calling (names are case-sensitive)","Whitelist language options in config parsing","Pass null to query instead of guessing a name"],"tags":["php","mbstring","polyfill","valueerror","language"],"backgroundTag":"invalid-enum-value","analyzedSha":"d3d318bad5e7a1bfbd026009c8bfb8d8f99ae6b6","analyzedAt":"2026-09-13T19:34:02.044Z","contentChangedAt":"2026-09-13T19:34:02.044Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}