{"record":{"id":"8cf2a4e8c0cd52cc","repo":"PHPOffice/PHPWord","slug":"name-is-not-a-valid-type","errorCode":null,"errorMessage":"\"{$name}\" is not a valid {$type}.","messagePattern":"\"(.+?)\" is not a valid (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/PhpWord/IOFactory.php","lineNumber":76,"sourceCode":"    }\n\n    /**\n     * Create new object.\n     *\n     * @param string $type\n     * @param string $name\n     * @param PhpWord $phpWord\n     *\n     * @return ReaderInterface|WriterInterface\n     */\n    private static function createObject($type, $name, $phpWord = null)\n    {\n        $class = \"PhpOffice\\\\PhpWord\\\\{$type}\\\\{$name}\";\n        if (class_exists($class) && self::isConcreteClass($class)) {\n            return new $class($phpWord);\n        }\n\n        throw new Exception(\"\\\"{$name}\\\" is not a valid {$type}.\");\n    }\n\n    /**\n     * Loads PhpWord from file.\n     *\n     * @param string $filename The name of the file\n     * @param string $readerName\n     *\n     * @return PhpWord $phpWord\n     */\n    public static function load($filename, $readerName = 'Word2007')\n    {\n        /** @var ReaderInterface $reader */\n        $reader = self::createReader($readerName);\n\n        return $reader->load($filename);\n    }\n","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/PHPOffice/PHPWord/blob/aef95c04151b5633cc505f672ddd6a71da900ee1/src/PhpWord/IOFactory.php#L58-L94","documentation":"IOFactory::createObject() maps \"PhpOffice\\PhpWord\\{$type}\\{$name}\" to a class (used by createReader with type 'Reader'). If the class does not exist or is not a concrete instantiable class, a PhpWord Exception is thrown. Effectively a whitelist+autoloader check for reader names like 'Word2007'.","triggerScenarios":"IOFactory::createReader('docx') (lowercase → class PhpWord\\Reader\\docx missing), createReader('ODText') where the Reader\\ODText class doesn't exist, or any name whose corresponding Reader class fails to autoload or is abstract/interface.","commonSituations":"Using format names/aliases that don't match a Reader class, typos, expecting readers for formats the library can't read (e.g. PDF), or composer autoloading not generating classmaps.","solutions":["Use an exact supported reader name: 'Word2007', 'ODText', 'RTF', 'HTML' (check src/PhpWord/Reader/ for available classes).","Ensure composer dump-autoload has run and the PhpWord package is installed correctly.","Verify the requested reader class exists and is concrete (createObject checks isConcreteClass).","Catch PhpWord Exception around createReader for dynamic format names."],"exampleFix":"// before\n$reader = IOFactory::createReader('docx');\n// after\n$reader = IOFactory::createReader('Word2007');","handlingStrategy":"validation","validationCode":"$readers = ['Word2007', 'ODText', 'RTF', 'HTML']; // classes present in src/PhpWord/Reader\nif (!in_array($name, $readers, true)) { throw new DomainException('Unsupported reader'); }","typeGuard":"function readerClassExists(string $name): bool { return class_exists('PhpOffice\\\\PhpWord\\\\Reader\\\\' . $name) && (new \\ReflectionClass('PhpOffice\\\\PhpWord\\\\Reader\\\\' . $name))->isInstantiable(); }","tryCatchPattern":"try { $reader = IOFactory::createReader($name); } catch (\\PhpOffice\\PhpWord\\Exception\\Exception $e) { log('unsupported reader: ' . $e->getMessage()); }","preventionTips":["Use reader names matching existing Reader classes exactly","Run composer dump-autoload after install/update","Don't expect readers for formats the library only writes (e.g. PDF)"],"tags":["phpword","reader","class-not-found","iofactory"],"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"}