Skip to content

Stdlib: DOMXPath — XPath queries on DOMDocument missing (ext/dom/xpath.c) #6066

Description

@PurHur

Category

stdlib

Problem

DOMDocument / DOMElement tree APIs are tracked in #3326, but XPath evaluation via DOMXPath is a separate php-src surface. Code using $xpath = new DOMXPath($doc); $xpath->query('//item') fails here because class_exists('DOMXPath', false) is false (verified 2026-06-05).

php-src reference

Repro (failure today)

Save as test/repro-maintainer/parity_domxpath.php:

<?php
$xml = '<root><item id="1">a</item><item id="2">b</item></root>';
$doc = new DOMDocument();
$doc->loadXML($xml);
var_export(class_exists('DOMXPath', false));
echo "\n";
$xpath = new DOMXPath($doc);
$nodes = $xpath->query('//item[@id="2"]');
echo $nodes->length, "\n";
echo $nodes->item(0)->textContent, "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/parity_domxpath.php
php bin/vm.php test/repro-maintainer/parity_domxpath.php
'
Runtime Expected Actual (2026-06-05)
Zend PHP true, 1, b —
bin/vm.php same fails earlier if DOMDocument missing (#3326); otherwise DOMXPath not found

Note: If #3326 is not landed, repro may fail on DOMDocument first — implement XPath after minimal DOM tree exists, or stub DOM in repro for isolated XPath unit tests.

Scope (PHP-in-PHP first)

Path Work
ext/dom/ (with #3326) DOMXPath class + query() / evaluate() VM builtins
lib/VM/BuiltinClasses.php register DOMXPath
libxml2 thin C ABI for xpath context if no PHP binding exists
Tests test/compliance/cases/stdlib/dom_xpath_query.phpt

Depends on #3326 for DOMDocument / DOMNodeList objects.

Done when

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter dom_xpath'

Links

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions