{"record":{"id":"eccf131370d9fb58","repo":"PHPOffice/PHPWord","slug":"invalid-part-type-type","errorCode":null,"errorMessage":"Invalid part type: {$type}","messagePattern":"Invalid part type: (.+?)","errorType":"exception","errorClass":"PhpOffice\\PhpWord\\Exception\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpWord/Writer/EPub3/Part.php","lineNumber":40,"sourceCode":"\n/**\n * Factory class for EPub3 parts.\n */\nclass Part\n{\n    /**\n     * Get the fully qualified class name for a specific part type.\n     *\n     * @param string $type The type of part (Content, Manifest, Meta, Mimetype)\n     *\n     * @return string The fully qualified class name\n     */\n    public static function getPartClass(string $type): string\n    {\n        $class = 'PhpOffice\\\\PhpWord\\\\Writer\\\\EPub3\\\\Part\\\\' . $type;\n\n        if (!class_exists($class)) {\n            throw new Exception(\"Invalid part type: {$type}\");\n        }\n\n        return $class;\n    }\n}\n","sourceCodeStart":22,"sourceCodeEnd":46,"githubUrl":"https://github.com/PHPOffice/PHPWord/blob/aef95c04151b5633cc505f672ddd6a71da900ee1/src/PhpWord/Writer/EPub3/Part.php#L22-L46","documentation":"EPub3 writer parts are resolved dynamically: getPartClass() maps a part type string to a class under PhpOffice\\PhpWord\\Writer\\EPub3\\Part\\. If the class does not exist the type string is not a supported part and the method throws. This guards against typos and unknown part names.","triggerScenarios":"Calling Part::getPartClass() with a type that has no matching class in the EPub3 Part namespace — misspelled names, wrong capitalization ('content' vs 'Content'), or a custom part whose class was never created.","commonSituations":"Custom extension code adding new EPub3 parts before creating the class; typos in the type argument; case-sensitivity mistakes; upgrading PhpWord where part classes were renamed.","solutions":["Use only part types whose classes exist under src/PhpWord/Writer/EPub3/Part/.","Fix capitalization — class names are case-sensitive ('Content', not 'content').","If adding a custom part, create the class in the Part namespace before resolving it.","Validate the type with class_exists before calling getPartClass."],"exampleFix":"// before\n$class = Part::getPartClass('content'); // class PhpOffice\\...\\Part\\content does not exist -> throws\n// after\n$class = Part::getPartClass('Content'); // matches PhpOffice\\PhpWord\\Writer\\EPub3\\Part\\Content","handlingStrategy":"validation","validationCode":"$validTypes = array_map(\n    fn($f) => pathinfo($f, PATHINFO_FILENAME),\n    glob(__DIR__ . '/vendor/phpoffice/phpword/src/PhpWord/Writer/EPub3/Part/*.php')\n);\n$valid = in_array($type, $validTypes, true);","typeGuard":"function isValidEpub3PartType(string $type): bool {\n    return class_exists('PhpOffice\\\\PhpWord\\\\Writer\\\\EPub3\\\\Part\\\\' . $type);\n}","tryCatchPattern":"try {\n    $class = Part::getPartClass($type);\n} catch (\\PhpOffice\\PhpWord\\Exception\\Exception $e) {\n    if (str_starts_with($e->getMessage(), 'Invalid part type')) {\n        $class = Part::getPartClass('Content'); // safe default\n    } else { throw $e; }\n}","preventionTips":["List src/PhpWord/Writer/EPub3/Part/ to see valid type names before calling.","Remember the type maps to a class name — exact case matters.","Validate user-supplied part types with class_exists before resolution.","When adding custom parts, create the class first, then reference the type."],"tags":["phpword","epub3","writer","class-not-found"],"backgroundTag":"class-not-found","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"}