[php-src] Issue #20282: \Dom\DocumentFragment;:getElementById() is not supported

From: Date: Fri, 24 Oct 2025 16:20:29 +0000
Subject: [php-src] Issue #20282: \Dom\DocumentFragment;:getElementById() is not supported
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-251113@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/20282 Author: cscott ### Description The following code: ```php <?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 ```plain 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

« previous php.bugs (#251113) next »