{"record":{"id":"f64bf919806bef9f","repo":"PHPOffice/PHPWord","slug":"no-phpword-assigned-contentxhtml","errorCode":null,"errorMessage":"No PhpWord assigned.","messagePattern":"No PhpWord assigned\\.","errorType":"exception","errorClass":"PhpOffice\\PhpWord\\Exception\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpWord/Writer/EPub3/Part/ContentXhtml.php","lineNumber":50,"sourceCode":"     * Get XML Writer.\n     *\n     * @return XMLWriter\n     */\n    protected function getXmlWriter()\n    {\n        $xmlWriter = new XMLWriter();\n        $xmlWriter->openMemory();\n\n        return $xmlWriter;\n    }\n\n    /**\n     * Write part content.\n     */\n    public function write(): string\n    {\n        if ($this->phpWord === null) {\n            throw new \\PhpOffice\\PhpWord\\Exception\\Exception('No PhpWord assigned.');\n        }\n\n        $xmlWriter = $this->getXmlWriter();\n\n        $xmlWriter->startDocument('1.0', 'UTF-8');\n        $xmlWriter->startElement('html');\n        $xmlWriter->writeAttribute('xmlns', 'http://www.w3.org/1999/xhtml');\n        $xmlWriter->writeAttribute('xmlns:epub', 'http://www.idpf.org/2007/ops');\n        $xmlWriter->startElement('head');\n        $xmlWriter->writeElement('title', $this->phpWord->getDocInfo()->getTitle() ?: 'Untitled');\n        $xmlWriter->endElement(); // head\n        $xmlWriter->startElement('body');\n\n        // Write sections content\n        foreach ($this->phpWord->getSections() as $section) {\n            $xmlWriter->startElement('div');\n            $xmlWriter->writeAttribute('class', 'section');\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/PHPOffice/PHPWord/blob/aef95c04151b5633cc505f672ddd6a71da900ee1/src/PhpWord/Writer/EPub3/Part/ContentXhtml.php#L32-L68","documentation":"A state guard in ContentXhtml::write(): the EPub3 content part's $phpWord property was never set, so there is no document to serialize into XHTML. This fires when write() is called on the part without first assigning a PhpWord instance (typically via the parent's setPhpWord()), e.g. when a part is written out of order or constructed standalone instead of through the normal EPub3 writer pipeline.","triggerScenarios":"Thrown at src/PhpWord/Writer/EPub3/Part/ContentXhtml.php:50 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Always obtain the part via the EPub3 writer (getWriterPart) so setPhpWord() is called for you.","Call setPhpWord($phpWord) on the part before invoking write()."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}