{"record":{"id":"f7ac7fd7cfad6856","repo":"PHPOffice/PhpSpreadsheet","slug":"cannot-get-shared-component-for-a-pseudo-border","errorCode":null,"errorMessage":"Cannot get shared component for a pseudo-border.","messagePattern":"Cannot get shared component for a pseudo-border\\.","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Style/Border.php","lineNumber":80,"sourceCode":"    /**\n     * Get the shared style component for the currently active cell in currently active sheet.\n     * Only used for style supervisor.\n     */\n    public function getSharedComponent(): self\n    {\n        /** @var Style $parent */\n        $parent = $this->parent;\n\n        /** @var Borders $sharedComponent */\n        $sharedComponent = $parent->getSharedComponent();\n\n        return match ($this->parentPropertyName) {\n            'bottom' => $sharedComponent->getBottom(),\n            'diagonal' => $sharedComponent->getDiagonal(),\n            'left' => $sharedComponent->getLeft(),\n            'right' => $sharedComponent->getRight(),\n            'top' => $sharedComponent->getTop(),\n            default => throw new PhpSpreadsheetException('Cannot get shared component for a pseudo-border.'),\n        };\n    }\n\n    /**\n     * Build style array from subcomponents.\n     *\n     * @param mixed[] $array\n     *\n     * @return mixed[]\n     */\n    public function getStyleArray(array $array): array\n    {\n        /** @var Style $parent */\n        $parent = $this->parent;\n\n        return $parent->getStyleArray([$this->parentPropertyName => $array]);\n    }\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Style/Border.php#L62-L98","documentation":"In supervisor mode a Border object forwards reads to the matching border of the shared style component held by its parent. Border::getSharedComponent() maps parentPropertyName ('bottom', 'diagonal', 'left', 'right', 'top') to that shared side; pseudo-borders ('allBorders', 'outline', 'inside') have no single underlying side, so the match() falls through to default and throws 'Cannot get shared component for a pseudo-border.' It fires when property reads are attempted through a pseudo-border attached to a supervisor style.","triggerScenarios":"Chaining $sheet->getStyle('A1')->getBorders()->getAllBorders()->getBorderStyle() (or any getter that routes through getSharedComponent) — the pseudo-border has no concrete side to read; similarly via getOutline()/getInside(); calling getSharedComponent() directly on a pseudo-border; reading a property on a pseudo-border in supervisor mode.","commonSituations":"Code that reads back formatting it previously applied via 'allBorders' arrays; generic style-inspection/reflection tooling that walks every Borders sub-object; conditional code that queries the border style of a range after setting outline borders.","solutions":["Read concrete sides instead of pseudo-borders: getBorders()->getTop()->getBorderStyle(), getBottom(), getLeft(), getRight().","Apply whole-outline/all formatting through applyFromArray (e.g. ['borders' => ['allBorders' => ['borderStyle' => Border::BORDER_THIN]]]) rather than reading pseudo-borders back.","Keep a record of what you applied in your own variables instead of interrogating pseudo-borders."],"exampleFix":"// before\n$borderStyle = $sheet->getStyle('A1')->getBorders()->getAllBorders()->getBorderStyle();\n// throws: Cannot get shared component for a pseudo-border.\n\n// after\n$borders = $sheet->getStyle('A1')->getBorders();\n$borderStyle = $borders->getTop()->getBorderStyle(); // concrete side\n// to SET all borders at once, use applyFromArray:\n$sheet->getStyle('A1')->applyFromArray([\n    'borders' => ['allBorders' => ['borderStyle' => \\PhpOffice\\PhpSpreadsheet\\Style\\Border::BORDER_THIN]],\n]);","handlingStrategy":"validation","validationCode":"// Read concrete sides only; never route property reads through a pseudo-border\n$borders = $sheet->getStyle('A1')->getBorders();\n$style = $borders->getTop()->getBorderStyle();\nif ($style === Border::BORDER_NONE) {\n    $style = $borders->getBottom()->getBorderStyle();\n}","typeGuard":"function isConcreteBorder(\\PhpOffice\\PhpSpreadsheet\\Style\\Border $b): bool\n{\n    return in_array($b->getParentPropertyName(), ['top', 'bottom', 'left', 'right', 'diagonal'], true);\n}","tryCatchPattern":"try {\n    $value = $border->getSharedComponent()->getBorderStyle();\n} catch (\\PhpOffice\\PhpSpreadsheet\\Exception $e) {\n    // pseudo-border: fall back to a concrete side\n    $value = $borders->getTop()->getBorderStyle();\n}","preventionTips":["Read border state via top/bottom/left/right getters only.","Apply 'allBorders'/'outline'/'inside' through applyFromArray, never read them back.","Track applied formatting in your own metadata instead of querying pseudo-borders."],"tags":["styles","borders","pseudo-border","supervisor","phpspreadsheet"],"backgroundTag":"invalid-style-component","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}