{"record":{"id":"4c83531a7dda6a46","repo":"PHPOffice/PHPWord","slug":"value-is-not-a-valid-value-for-calledclass-possible-values","errorCode":null,"errorMessage":"$value is not a valid value for $calledClass, possible values are ' . implode(', ', $values)","messagePattern":"\\$value is not a valid value for \\$calledClass, possible values are ' \\. implode\\(', ', \\$values\\)","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/PhpWord/Shared/AbstractEnum.php","lineNumber":77,"sourceCode":"    public static function isValid($value)\n    {\n        $values = array_values(self::getConstants());\n\n        return in_array($value, $values, true);\n    }\n\n    /**\n     * Validates that the value passed is a valid value.\n     *\n     * @param string $value\n     */\n    public static function validate($value): void\n    {\n        if (!self::isValid($value)) {\n            $calledClass = static::class;\n            $values = array_values(self::getConstants());\n\n            throw new InvalidArgumentException(\"$value is not a valid value for $calledClass, possible values are \" . implode(', ', $values));\n        }\n    }\n}\n","sourceCodeStart":59,"sourceCodeEnd":81,"githubUrl":"https://github.com/PHPOffice/PHPWord/blob/aef95c04151b5633cc505f672ddd6a71da900ee1/src/PhpWord/Shared/AbstractEnum.php#L59-L81","documentation":"AbstractEnum::validate() is the guard used by PhpWord value objects (alignment, vertical alignment, line rule, unit). When a setter receives a value not among the class constants, it throws InvalidArgumentException listing the class name and every accepted constant value. It exists to fail fast on invalid enum-style inputs rather than silently producing malformed document XML.","triggerScenarios":"Calling setTextAlignment()/setVAlign()/setLineRule()/setUnit() (or anything that funnels into AbstractEnum::validate) with a string that is not one of the class constants, e.g. setVAlign('centered') instead of 'center', or setLineRule('exact') instead of LineRule::EXACT. Case-sensitivity matters: 'Center' or 'CENTER' will not match.","commonSituations":"Hand-written style configuration copied from Word UI wording instead of the library constants; typo'd constant names; values read from user input or config files without whitelisting; upgrading where a constant was renamed.","solutions":["Look at the exception message: it lists all valid values for the called class; use one of them exactly (case-sensitive).","Use the class constants (e.g. Alignment::CENTER, LineRule::AUTO) instead of raw strings.","Normalize/whitelist user or config input against the enum's isValid() before calling the setter.","If a value seems missing, check whether the constant was renamed in your PhpWord version."],"exampleFix":"// before\n$cell->setVAlign('middle');\n// after\nuse PhpOffice\\PhpWord\\SimpleType\\VerticalJc;\n$cell->setVAlign(VerticalJc::CENTER); // 'center'","handlingStrategy":"validation","validationCode":"use PhpOffice\\PhpWord\\SimpleType\\VerticalJc;\nif (!in_array($value, VerticalJc::getConstants(), true)) {\n    throw new InvalidArgumentException(\"Invalid vAlign: $value\");\n}\n$cell->setVAlign($value);","typeGuard":null,"tryCatchPattern":"try {\n    $cell->setVAlign($value);\n} catch (\\InvalidArgumentException $e) {\n    $logger->warning('Invalid alignment value', ['value' => $value, 'msg' => $e->getMessage()]);\n    $cell->setVAlign(VerticalJc::CENTER); // safe default\n}","preventionTips":["Always use the library's constant classes instead of raw strings","Whitelist/normalize external input against the enum constants before setting","Copy values from the exception message's list of allowed values when debugging"],"tags":["phpword","enum","invalid-argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"aef95c04151b5633cc505f672ddd6a71da900ee1","analyzedAt":"2026-09-14T10:53:58.933Z","contentChangedAt":"2026-09-14T10:53:58.933Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}