phar-io/manifest · error · ManifestElementException

Element missing

Error message

Element %s missing

What it means

ManifestElement::getChildByName searches for a single named child element in the phar.io namespace and throws ManifestElementException('Element %s missing') when none is found. It backs getExtensionElement, getLicenseElement and getPHPElement, so the error means a required nested section (extension, license, or php inside <requires>) is absent.

Solutions

  1. Add the missing child element (e.g. <license type="BSD-3-Clause"/>) inside its parent
  2. Check the parent element in the message is the one you intended to query
  3. Regenerate the manifest with a current build tool
  4. Validate against the phar.io manifest XSD before use

Example fix

// before
<copyright><author name="A"/></copyright>
// after
<copyright><author name="A"/><license type="BSD-3-Clause"/></copyright>
Defensive patterns

Strategy: try-catch

Validate before calling

if ($copyright->getElementsByTagNameNS('https://phar.io/manifest', 'license')->length === 0) { throw new RuntimeException('No <license> element'); }

Type guard

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

Try / catch

try { $license = $copyright->getLicenseElement(); } catch (ManifestElementException $e) { log_warning('Manifest lacks license info'); $license = null; }

Prevention

When it happens

Trigger: Calling getLicenseElement() on the copyright element, getPHPElement()/getExtensionElement() on the requires element, when the corresponding child element is not present in the manifest XML.

Common situations: Requires section lacking a <php> constraint; copyright section without <license>; manifests edited to drop license info; manifests produced by tools predating a required child element.

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/88b01c5a6a93de17. Report an issue: GitHub.

Appendix: source

Thrown at src/xml/ManifestElement.php:49

                    'Attribute %s not set on element %s',
                    $name,
                    $this->element->localName
                )
            );
        }

        return $this->element->getAttribute($name);
    }

    protected function hasAttribute(string $name): bool {
        return $this->element->hasAttribute($name);
    }

    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;
    }

View on GitHub (pinned to c581d4941e)