{"record":{"id":"6159dc11a5de88f8","repo":"PHPOffice/PHPWord","slug":"type-must-be-start-or-end","errorCode":null,"errorMessage":"Type must be \"start\" or \"end\"","messagePattern":"Type must be \"start\" or \"end\"","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/PhpWord/Reader/Word2007/AbstractPart.php","lineNumber":159,"sourceCode":"    /**\n     * Set comment references.\n     *\n     * @param array<string, array<string, null|AbstractElement>> $commentRefs\n     */\n    public function setCommentReferences(array $commentRefs): self\n    {\n        $this->commentRefs = $commentRefs;\n\n        return $this;\n    }\n\n    /**\n     * Set comment reference.\n     */\n    private function setCommentReference(string $type, string $id, AbstractElement $element): self\n    {\n        if (!in_array($type, ['start', 'end'])) {\n            throw new InvalidArgumentException('Type must be \"start\" or \"end\"');\n        }\n\n        if (!array_key_exists($id, $this->commentRefs)) {\n            $this->commentRefs[$id] = [\n                'start' => null,\n                'end' => null,\n            ];\n        }\n        $this->commentRefs[$id][$type] = $element;\n\n        return $this;\n    }\n\n    /**\n     * Get comment reference.\n     *\n     * @return array<string, null|AbstractElement>\n     */","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/PHPOffice/PHPWord/blob/aef95c04151b5633cc505f672ddd6a71da900ee1/src/PhpWord/Reader/Word2007/AbstractPart.php#L141-L177","documentation":"AbstractPart::setCommentReference validates that a comment reference type is either 'start' or 'end'. Any other value found in commentRangeStart/commentRangeEnd parsing is rejected with this InvalidArgumentException.","triggerScenarios":"Parsing a document.xml containing a comment range element whose local name is neither commentRangeStart nor commentRangeEnd, so $type is unexpected when readRun dispatches to setCommentReference.","commonSituations":"Malformed or non-standard comment markup from third-party docx generators; corrupted document.xml; future OOXML elements mis-detected as comment ranges.","solutions":["Update PhpWord in case newer versions handle the element","Inspect the document's commentRangeStart/End markup for anomalies and fix the source document","Re-save the document in Word to normalize the XML","Wrap load() in try-catch if comments are optional for your workflow"],"exampleFix":"// before\n$type = $element->nodeName; // e.g. 'commentRangeFoo'\n$this->setCommentReference($type, $id, $run);\n// after\nif (in_array($type, ['commentRangeStart', 'commentRangeEnd'], true)) {\n    $this->setCommentReference($type === 'commentRangeStart' ? 'start' : 'end', $id, $run);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isCommentRangeType(string $t): bool { return $t === 'start' || $t === 'end'; }","tryCatchPattern":"try { $phpWord = \\PhpOffice\\PhpWord\\IOFactory::load($docFile); } catch (\\InvalidArgumentException $e) { if (str_contains($e->getMessage(), 'Type must be')) { // treat as malformed comments, continue without them } throw $e; }","preventionTips":["Validate source documents in Word before automated processing","Strip malformed comment ranges if comments are not needed","Keep PhpWord current for OOXML edge-case fixes"],"tags":["phpword","word2007","comments","validation"],"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"}