phar-io/manifest · error · ManifestDocumentException
Element missing
Error message
Element %s missing
What it means
ManifestDocument::fetchElementByName looks up a direct child element by name in the phar.io namespace via getElementsByTagNameNS and throws ManifestDocumentException('Element %s missing') when no DOMElement is found. It backs getContainsElement, getCopyrightElement, getRequiresElement and getBundlesElement, so a top-level required section (contains, copyright, requires, bundles) is absent from the manifest.
Solutions
- Add the missing required element (e.g. <requires>) to the manifest XML
- Ensure all elements use the phar.io namespace xmlns="https://phar.io/manifest"
- Regenerate the manifest with a current version of the build tool
- Check which element name appears in the exception message and verify its spelling
Example fix
// before <phar xmlns="https://phar.io/manifest"><contains>...</contains></phar> // after <phar xmlns="https://phar.io/manifest"><contains>...</contains><requires><php version="8.1"/></requires></phar>
Defensive patterns
Strategy: try-catch
Validate before calling
$dom->loadXML($xml); if ($dom->getElementsByTagNameNS('https://phar.io/manifest', 'requires')->length === 0) { throw new RuntimeException('Manifest lacks <requires> element'); } Type guard
function hasElement(DOMDocument $dom, string $name): bool { return $dom->getElementsByTagNameNS('https://phar.io/manifest', $name)->length > 0; } Try / catch
try { $requires = $doc->getRequiresElement(); } catch (ManifestDocumentException $e) { log_warning('Manifest section missing: ' . $e->getMessage()); $requires = null; } Prevention
- Use full manifests containing contains/copyright/requires/bundles sections
- Ensure every element carries the phar.io namespace
- Validate against the official manifest XSD before loading
When it happens
Trigger: Accessing e.g. $doc->getRequiresElement() (or contains/copyright/bundles) on a ManifestDocument whose XML lacks that element under the phar.io namespace.
Common situations: Minimal/incomplete manifests generated by older tool versions missing newer required sections; manifests with elements in the wrong namespace so getElementsByTagNameNS finds nothing; hand-trimmed manifests.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Element missing
- Element(s) missing
- Processing string failed
- $t->getMessage()
- Not a phar.io manifest document
AI-assisted analysis of phar-io/manifest@c581d4941e (2026-09-14).
Data as JSON: /api/errors/2e92fd1dec3c2d44.
Report an issue: GitHub.
Appendix: source
Thrown at src/xml/ManifestDocument.php:108
public function getBundlesElement(): BundlesElement {
return new BundlesElement(
$this->fetchElementByName('bundles')
);
}
private function ensureCorrectDocumentType(DOMDocument $dom): void {
$root = $dom->documentElement;
if ($root->localName !== 'phar' || $root->namespaceURI !== self::XMLNS) {
throw new ManifestDocumentException('Not a phar.io manifest document');
}
}
private function fetchElementByName(string $elementName): DOMElement {
$element = $this->dom->getElementsByTagNameNS(self::XMLNS, $elementName)->item(0);
if (!$element instanceof DOMElement) {
throw new ManifestDocumentException(
sprintf('Element %s missing', $elementName)
);
}
return $element;
}
}
View on GitHub (pinned to c581d4941e)