Skip to content

Stdlib: XMLReader::lookupNamespace() missing — Fatal undefined method (ext/xmlreader/php_xmlreader.c) #19396

Closed

Description

@PurHur

Category

Stdlib · php-src-strict / XMLReader namespace lookup

Problem

Zend XMLReader::lookupNamespace($prefix) resolves in-scope xmlns bindings at the current node. VM has no such method, so namespace-aware pull parsing cannot resolve prefixes after read().

Repro Zend 8.2+ (2026-07-16) VM (2026-07-16)
$r->XML('<r xmlns:p="urn:x" …>'); $r->read(); $r->lookupNamespace('p') 'urn:x' Error: Call to undefined method XMLReader::lookupNamespace()

php-src reference

PHP implementation target

  • ext/xmlreader/VmXmlReader.php — register lookupNamespace
  • Track xmlns declarations on the reader stack in XmlReaderState / tokenizer (VmXmlReader::tokenize) and resolve prefix → URI in PHP
  • Prefer PHP-in-PHP; no new C in runtime/

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
cat > /tmp/xr_lookup.php << "PHP"
<?php
$r = new XMLReader();
$r->XML("<r xmlns:p=\"urn:x\" p:a=\"1\"><c/></r>");
$r->read();
echo "lookupNs=", var_export($r->lookupNamespace("p"), true), "\n";
PHP
php /tmp/xr_lookup.php
php bin/vm.php /tmp/xr_lookup.php
'

Done when

  • lookupNamespace('p') returns 'urn:x' on the repro; unknown prefix matches Zend (null)
  • Compliance .phpt under test/compliance/cases/xmlreader/
  • php-src-strict; no php-compiler-strict shortcut

Activity

  1. added
    bugSomething isn't working
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 16, 2026
  2. PurHur commented on Jul 17, 2026

    @PurHur
    OwnerAuthor

    Merged via PR #19875.

    Fix: Tokenizer ns stack + XmlReaderEvent::$nsScope; XMLReader::lookupNamespace($prefix) resolves like php-src xmlTextReaderLookupNamespace / xmlSearchNs (PHP-in-PHP; no new C).

    Verification:

    php bin/vm.php test/repro/maintainer_gap_xmlreader_lookup_namespace.php  # lookupNs='urn:x' …
    php bin/jit.php test/repro/maintainer_gap_xmlreader_lookup_namespace.php
    ./script/phpunit.sh --filter lookup_namespace   # OK 3 tests
    ./script/phpunit.sh --filter XmlReaderTest      # OK 11 tests
    php script/bootstrap-inventory.php --check      # OK 5297/5297
    
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 machinebugSomething isn't workingenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions