phar-io/manifest · error · ManifestElementException

Element(s) missing

Error message

Element(s) %s missing

What it means

ManifestElement::getChildrenByName retrieves a list of child elements by name in the phar.io namespace and throws ManifestElementException('Element(s) %s missing') when the resulting DOMNodeList has length 0. It backs getComponentElements, getAuthorElements and getExtElements, meaning at least one such child is mandatory by the library's contract.

Solutions

  1. Add at least one child element of the named kind (e.g. an <author>) to the parent element
  2. Regenerate the manifest with a current build tool so required collections are emitted
  3. Validate the manifest against the phar.io XSD before loading
  4. Guard the call site with try-catch on ManifestElementException if the section may legitimately be absent in your data

Example fix

// before
<bundles></bundles>
// after
<bundles><component name="acme/lib" version="1.2.0" url="https://example.com/acme.phar"/></bundles>
Defensive patterns

Strategy: validation

Validate before calling

if ($bundles->getElementsByTagNameNS('https://phar.io/manifest', 'component')->length === 0) { throw new RuntimeException('Bundles section has no components'); }

Type guard

function childCount(DOMElement $el, string $name): int { return $el->getElementsByTagNameNS('https://phar.io/manifest', $name)->length; }

Try / catch

try { $authors = $copyright->getAuthorElements(); } catch (ManifestElementException $e) { $authors = []; log_warning($e->getMessage()); }

Prevention

When it happens

Trigger: Calling getAuthorElements() on the copyright element, getComponentElements() on the bundles element, or getExtElements() on an extension element when no matching child elements exist in the manifest.

Common situations: Bundles section with no <component> entries; extension element declaring no <ext> requirements; copyright element without any <author>; manifests pruned by hand or by an incomplete generator.

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


AI-assisted analysis of phar-io/manifest@c581d4941e (2026-09-14). Data as JSON: /api/errors/2fa8109a330ba10f. Report an issue: GitHub.

Appendix: source

Thrown at src/xml/ManifestElement.php:61

    }

    protected function getChildByName(string $elementName): DOMElement {
        $element = $this->element->getElementsByTagNameNS(self::XMLNS, $elementName)->item(0);

        if (!$element instanceof DOMElement) {
            throw new ManifestElementException(
                sprintf('Element %s missing', $elementName)
            );
        }

        return $element;
    }

    protected function getChildrenByName(string $elementName): DOMNodeList {
        $elementList = $this->element->getElementsByTagNameNS(self::XMLNS, $elementName);

        if ($elementList->length === 0) {
            throw new ManifestElementException(
                sprintf('Element(s) %s missing', $elementName)
            );
        }

        return $elementList;
    }

    protected function hasChild(string $elementName): bool {
        return $this->element->getElementsByTagNameNS(self::XMLNS, $elementName)->length !== 0;
    }
}

View on GitHub (pinned to c581d4941e)