{"record":{"id":"ad141b80570b4c7b","repo":"phar-io/manifest","slug":"not-a-phar-io-manifest-document","errorCode":null,"errorMessage":"Not a phar.io manifest document","messagePattern":"Not a phar\\.io manifest document","errorType":"exception","errorClass":"ManifestDocumentException","httpStatus":null,"severity":"error","filePath":"src/xml/ManifestDocument.php","lineNumber":100,"sourceCode":"            $this->fetchElementByName('requires')\n        );\n    }\n\n    public function hasBundlesElement(): bool {\n        return $this->dom->getElementsByTagNameNS(self::XMLNS, 'bundles')->length === 1;\n    }\n\n    public function getBundlesElement(): BundlesElement {\n        return new BundlesElement(\n            $this->fetchElementByName('bundles')\n        );\n    }\n\n    private function ensureCorrectDocumentType(DOMDocument $dom): void {\n        $root = $dom->documentElement;\n\n        if ($root->localName !== 'phar' || $root->namespaceURI !== self::XMLNS) {\n            throw new ManifestDocumentException('Not a phar.io manifest document');\n        }\n    }\n\n    private function fetchElementByName(string $elementName): DOMElement {\n        $element = $this->dom->getElementsByTagNameNS(self::XMLNS, $elementName)->item(0);\n\n        if (!$element instanceof DOMElement) {\n            throw new ManifestDocumentException(\n                sprintf('Element %s missing', $elementName)\n            );\n        }\n\n        return $element;\n    }\n}\n","sourceCodeStart":82,"sourceCodeEnd":116,"githubUrl":"https://github.com/phar-io/manifest/blob/c581d4941e196459bf76c945a8ca922963a66708/src/xml/ManifestDocument.php#L82-L116","documentation":"ManifestDocument::ensureCorrectDocumentType validates that the parsed document's root element has localName 'phar' and the expected phar.io namespace (self::XMLNS). If not, it throws ManifestDocumentException('Not a phar.io manifest document'). The XML may be perfectly well-formed — it just isn't a phar.io manifest.","triggerScenarios":"Calling ManifestDocument::fromString()/fromFile() on XML whose root element is not <phar> in the phar.io namespace — e.g. wrong root name, missing xmlns, or a completely different XML file (composer.json-style XML, arbitrary config).","commonSituations":"Pointing phar.io tooling (e.g. phpab, phive) at the wrong file; a manifest saved without the xmlns=\"https://phar.io/...\" attribute; hand-edited manifest with renamed root element.","solutions":["Check the file being loaded is actually a phar.io manifest XML","Ensure the root element is <phar xmlns=\"https://phar.io/manifest\"> (the library's expected XMLNS)","Regenerate the manifest with the original build tool instead of hand-editing","Inspect the root element: $dom->documentElement->localName / namespaceURI"],"exampleFix":"// before (manifest.xml)\n<manifest>...</manifest>\n// after\n<phar xmlns=\"https://phar.io/manifest\">...</phar>","handlingStrategy":"validation","validationCode":"$dom = new DOMDocument(); $dom->loadXML($xml); $root = $dom->documentElement; if ($root->localName !== 'phar' || $root->namespaceURI !== 'https://phar.io/manifest') { throw new RuntimeException('Not a phar.io manifest'); }","typeGuard":"function isPharManifest(DOMDocument $dom): bool { $r = $dom->documentElement; return $r !== null && $r->localName === 'phar' && $r->namespaceURI === 'https://phar.io/manifest'; }","tryCatchPattern":"try { $doc = ManifestDocument::fromFile($path); } catch (ManifestDocumentException $e) { if (str_contains($e->getMessage(), 'Not a phar.io manifest')) { /* wrong file type handling */ } throw $e; }","preventionTips":["Confirm you are loading the phar manifest, not another XML/config file","Keep xmlns=\"https://phar.io/manifest\" on the root <phar> element","Regenerate manifests with the official tool rather than hand-editing"],"tags":["xml","manifest","schema-validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"c581d4941e196459bf76c945a8ca922963a66708","analyzedAt":"2026-09-14T11:08:47.165Z","contentChangedAt":"2026-09-14T11:08:47.165Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}