php / php/php-src

\Dom\DocumentFragment::getElementById() is not supported

Open
#20,282 0 comments 0 reactions 0 assignees View on GitHub

@ndossche is already working on this.

Since Oct 24, 2025.

  • #20284 by @ndossche — open
Extension: dom Feature Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php
$d = \Dom\HTMLDocument::createFromString('<p id="a">b</p><p id="a">c</p>');
$df = $d->createDocumentFragment();
$df->getElementById('a');

Resulted in this output:

  Error  Call to undefined method Dom\DocumentFragment::getElementById().

But I expected this output instead:

(no output)

This method is present in the DOM spec: https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/getElementById and the similar method ::querySelector is implemented; I can't tell if querySelector actually uses the ID index though or does a linear scan through the fragment. (Aka, this method should not just be implemented, it is expected to have O(1) performance.)

PHP Version
PHP 8.4.13 (cli) (built: Oct  1 2025 20:34:15) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.13, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.13, Copyright (c), by Zend Technologies
Operating System

Ubuntu 24.04.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the linked pull request and the existing Dom\DocumentFragment::querySelector implementation mentioned in the issue. Consult the DOM specification for getElementById() semantics, including duplicate IDs and the expected lookup behavior; done means the method is available and returns the matching fragment element as specified.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.