{"record":{"id":"cfcd80aa69aef03a","repo":"PHPOffice/PhpSpreadsheet","slug":"cell-coordinate-can-not-be-zero-length-string","errorCode":null,"errorMessage":"Cell coordinate can not be zero-length string.","messagePattern":"Cell coordinate can not be zero-length string\\.","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Worksheet/Worksheet.php","lineNumber":2975,"sourceCode":"\n    /**\n     * Remove comment from cell.\n     *\n     * @param array{0: int, 1: int}|CellAddress|string $cellCoordinate Coordinate of the cell as a string, eg: 'C5';\n     *               or as an array of [$columnIndex, $row] (e.g. [3, 5]), or a CellAddress object.\n     *\n     * @return $this\n     */\n    public function removeComment(CellAddress|string|array $cellCoordinate): self\n    {\n        $cellAddress = Functions::trimSheetFromCellReference(Validations::validateCellAddress($cellCoordinate));\n\n        if (Coordinate::coordinateIsRange($cellAddress)) {\n            throw new Exception('Cell coordinate string can not be a range of cells.');\n        } elseif (str_contains($cellAddress, '$')) {\n            throw new Exception('Cell coordinate string must not be absolute.');\n        } elseif ($cellAddress == '') {\n            throw new Exception('Cell coordinate can not be zero-length string.');\n        }\n        // Check if we have a comment for this cell and delete it\n        if (isset($this->comments[$cellAddress])) {\n            unset($this->comments[$cellAddress]);\n        }\n\n        return $this;\n    }\n\n    /**\n     * Get comment for cell.\n     *\n     * @param array{0: int, 1: int}|CellAddress|string $cellCoordinate Coordinate of the cell as a string, eg: 'C5';\n     *               or as an array of [$columnIndex, $row] (e.g. [3, 5]), or a CellAddress object.\n     */\n    public function getComment(CellAddress|string|array $cellCoordinate, bool $attachNew = true): Comment\n    {\n        $cellAddress = Functions::trimSheetFromCellReference(Validations::validateCellAddress($cellCoordinate));","sourceCodeStart":2957,"sourceCodeEnd":2993,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/Worksheet.php#L2957-L2993","documentation":"removeComment() rejects coordinates that are empty after sheet-prefix trimming. An empty string can neither address an existing comment nor serve as a storage key, so removeComment('') (or 'Sheet1!', which Functions::trimSheetFromCellReference() reduces to '') throws before the comments map is consulted.","triggerScenarios":"removeComment(''); removeComment('Summary!') where only the sheet prefix was present; coordinates built from missing array keys or null variables stringified to ''.","commonSituations":"Iterating header maps or user-supplied column lists where some keys are absent; dynamic code that assembles coordinates from possibly-empty variables.","solutions":["Guard for empty strings before calling and skip blank entries.","When concatenating sheet-prefixed refs, validate the cell part is non-empty.","Default missing config to a real coordinate or branch around the call."],"exampleFix":"// before\n$sheet->removeComment($headers['note_col'] ?? ''); // '' when key missing -> throws\n\n// after\n$noteCol = $headers['note_col'] ?? null;\nif (is_string($noteCol) && $noteCol !== '') {\n    $sheet->removeComment($noteCol);\n}","handlingStrategy":"validation","validationCode":"if ($coord === null || $coord === '' || str_ends_with($coord, '!')) {\n    // no usable cell address: skip\n} else {\n    $sheet->removeComment($coord);\n}","typeGuard":"/** Empty strings and bare sheet prefixes ('Sheet1!') are not cells. */\nfunction isNonEmptyCoordinate(?string $address): bool\n{\n    return is_string($address) && $address !== '' && !str_ends_with($address, '!');\n}","tryCatchPattern":null,"preventionTips":["Skip blank coordinates in loops over optional config instead of calling anyway.","When concatenating 'Sheet!' . $cell, assert $cell is non-empty first.","Treat missing config keys as 'no comment to remove', not as an empty-string call."],"tags":["phpspreadsheet","worksheet","comment","empty-argument","argument-validation"],"backgroundTag":"invalid-cell-reference","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}