Skip to content

Stdlib: DOMDocument::getElementById() after loadHTML() — HTML id attribute not indexed (ext/dom/document.c) #15251

Closed

Description

@PurHur

Category

stdlib · php-src-strict · ext/dom HTML lookup gap

Problem

After DOMDocument::loadHTML(), elements with an HTML id attribute are not found by getElementById(). Zend returns the matching element; VM returns null.

setIdAttribute() + XML DTD path works (#14493), but ordinary HTML id="..." from loadHTML() must also resolve without manual ID registration.

Verified 2026-07-03 on master.

php-src reference

PHP implementation target

  • ext/dom/VmDom.php — index id attributes during loadHTML() parse (or libxml HTML ID table bridge)
  • Reuse existing manual ID map from DOMElement::setIdAttribute() where possible
  • PHP-in-PHP + thin libxml bridge only

Repro (verified 2026-07-03)

./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_dom_loadhtml_get_element_by_id.php
# fail: getElementById null (exit 1)
# Zend: ok

Repro: test/repro/maintainer_gap_dom_loadhtml_get_element_by_id.php

Related: closed #14378 (method exists), #14493 (setIdAttribute), #14356 (loadHTML).

Done when

  • loadHTML('<p id="target">…</p>') then getElementById('target') returns element with correct textContent
  • XML/DOM without HTML id still returns null when no ID map (existing compliance)
  • Repro exits 0; compliance guard under test/compliance/cases/dom/ or stdlib/

Activity

  1. added
    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 3, 2026
  2. PurHur commented on Jul 3, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — batch (issue #15251)

  3. added a commit that references this issue on Jul 3, 2026
    2737241
  4. PurHur commented on Jul 3, 2026

    @PurHur
    OwnerAuthor

    Merged in #15306. loadHTML id indexing + compliance guard green.

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 appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions