{"record":{"id":"6136c49389f6d2a8","repo":"PHPOffice/PhpSpreadsheet","slug":"coordinate-no-longer-exists","errorCode":null,"errorMessage":"Coordinate no longer exists","messagePattern":"Coordinate no longer exists","errorType":"exception","errorClass":"SpreadsheetException","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Cell/Cell.php","lineNumber":169,"sourceCode":"\n        return $parent->getCurrentRow();\n    }\n\n    /**\n     * Get cell coordinate.\n     *\n     * @throws SpreadsheetException\n     */\n    public function getCoordinate(): string\n    {\n        $parent = $this->parent;\n        if ($parent !== null) {\n            $coordinate = $parent->getCurrentCoordinate();\n        } else {\n            $coordinate = null;\n        }\n        if ($coordinate === null) {\n            throw new SpreadsheetException('Coordinate no longer exists');\n        }\n\n        return $coordinate;\n    }\n\n    /**\n     * Get cell value.\n     */\n    public function getValue(): mixed\n    {\n        return $this->value;\n    }\n\n    public function getValueString(): string\n    {\n        return StringHelper::convertToString($this->value, false);\n    }\n","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Cell/Cell.php#L151-L187","documentation":"getCoordinate() asks the parent Cells collection for the coordinate under which this cell is currently tracked (getCurrentCoordinate()). If the cell has no parent, or the collection no longer records a current coordinate for it (cell detached, collection emptied or replaced), $coordinate is null and the exception fires. Like the row number, the coordinate string lives in the collection, not in the Cell.","triggerScenarios":"Calling getCoordinate() on a Cell held after worksheet removal or spreadsheet teardown; on a Cell cloned or re-created outside a collection; after the collection's current-coordinate pointer was reset or the cell was deleted from the collection.","commonSituations":"Keeping Cell objects in arrays/maps keyed for later writing while sheets get removed or rebuilt; processing cells inside jobs that outlive the spreadsheet instance; debugging sessions where a cell variable is inspected after the workbook was discarded.","solutions":["Carry the coordinate string you used to fetch the cell ('B4') through your pipeline instead of the Cell object","Guard with $cell->getParent() !== null before calling getCoordinate()","Re-fetch via $sheet->getCell($coord) from a live worksheet when the coordinate is needed again"],"exampleFix":"// before\n$cells[] = $sheet->getCell('A1');\nunset($spreadsheet);\nforeach ($cells as $cell) { $coord = $cell->getCoordinate(); } // throws\n\n// after\n$coords = ['A1'];\nunset($spreadsheet);\n// coordinates are plain strings and survive teardown","handlingStrategy":"validation","validationCode":"$coord = 'B4';\n$cell = $sheet->getCell($coord);\n// ... later, after possible teardown, reuse $coord (plain string) instead of $cell->getCoordinate()","typeGuard":"function cellHasLiveCoordinate(Cell $cell): bool\n{\n    return $cell->getParent() !== null;\n}","tryCatchPattern":"try {\n    $coord = $cell->getCoordinate();\n} catch (SpreadsheetException $e) {\n    $coord = $fallbackCoord; // coordinate captured at fetch time\n}","preventionTips":["Treat the coordinate string, not the Cell, as the durable identifier in your data structures","Re-derive cells from coordinates on a live worksheet each processing stage","Avoid keeping Cell instances in long-lived caches, queues, or closures"],"tags":["phpspreadsheet","cell","coordinate","detached-object"],"backgroundTag":"detached-object-access","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}