{"record":{"id":"d4f525e4ccaed1e8","repo":"PHPOffice/PHPWord","slug":"invalid-style-value-value-options","errorCode":null,"errorMessage":"Invalid style value: {$value} Options:","messagePattern":"Invalid style value: (.+?) Options:","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/PhpWord/Style/AbstractStyle.php","lineNumber":308,"sourceCode":"            $value = $default;\n        }\n\n        return $value;\n    }\n\n    /**\n     * Set enum value.\n     *\n     * @param mixed $value\n     * @param array $enum\n     * @param mixed $default\n     *\n     * @return mixed\n     */\n    protected function setEnumVal($value = null, $enum = [], $default = null)\n    {\n        if ($value != null && trim($value) != '' && !empty($enum) && !in_array($value, $enum)) {\n            throw new InvalidArgumentException(\"Invalid style value: {$value} Options:\" . implode(',', $enum));\n        } elseif ($value === null || trim($value) == '') {\n            $value = $default;\n        }\n\n        return $value;\n    }\n\n    /**\n     * Set object value.\n     *\n     * @param mixed $value\n     * @param mixed &$style\n     *\n     * @return mixed\n     */\n    protected function setObjectVal($value, string $styleName, &$style)\n    {\n        $styleClass = substr(static::class, 0, (int) strrpos(static::class, '\\\\')) . '\\\\' . $styleName;","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/PHPOffice/PHPWord/blob/aef95c04151b5633cc505f672ddd6a71da900ee1/src/PhpWord/Style/AbstractStyle.php#L290-L326","documentation":"AbstractStyle::setEnumVal validates that a style value is one of the allowed enumerated options for that style property; if the value is non-empty and not in the enum, it throws InvalidArgumentException listing the valid options. It is the generic enum validator for all PhpWord styles.","triggerScenarios":"Setting a style property via setters like setType, setPos, setHPos, setVPos, setHPosRelTo, setVPosRelTo with a string not present in the style's allowed constants, e.g. (new Tab())->setType('middle') when only 'clear','left','center','right','decimal','bar','num' are accepted.","commonSituations":"Typo in style constant ('Center' vs 'center'); copying values from OOXML documentation that are not supported by PhpWord; case-sensitivity issues; passing user input directly into style setters.","solutions":["Use the style class's constants (e.g. Tab::TAB_STOP_TYPE_CENTER) instead of literal strings","Check the exception message for the exact list of accepted options and correct the value","Normalize user input (trim, lowercase) and map it to a valid enum value before calling the setter"],"exampleFix":"// before\n$tab->setType('middle');\n// after\n$tab->setType(Tab::TAB_STOP_TYPE_CENTER); // 'center'","handlingStrategy":"validation","validationCode":"$allowed = ['clear','left','center','right','decimal','bar','num'];\nif (!in_array($value, $allowed, true)) {\n    throw new ValueError(\"Tab type must be one of: \" . implode(',', $allowed));\n}\n$tab->setType($value);","typeGuard":null,"tryCatchPattern":"try {\n    $style->setType($value);\n} catch (\\InvalidArgumentException $e) {\n    // fall back to a safe default enum value\n    $style->setType($style::DEFAULT_CONSTANT);\n}","preventionTips":["Always use the class constants instead of string literals","Normalize/trim user input before passing to style setters","Write a unit test per style property enumerating accepted values"],"tags":["validation","style","enum"],"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"}