[php-src] Issue #25210: Dom\HTMLDocument::querySelectorAll() returns duplicates for selector lists
| From: | phcorp | Date: | Thu, 05 Nov 2026 14:35:46 +0000 |
| Subject: | [php-src] Issue #25210: Dom\HTMLDocument::querySelectorAll() returns duplicates for selector lists | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-254019@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/25210
Author: phcorp
### Description
Dom\HTMLDocument::querySelectorAll() returns an element once per selector of a selector
list it matches. The DOM standard says the result holds each element once, in tree order
("scope-match a selectors string" returns a set).
```php
<?php
$d = Dom\HTMLDocument::createFromString('<!doctype
html><ul><li>a<ol><li
id="x">b</li></ol></li></ul>');
$ids = [];
foreach ($d->querySelectorAll('ul li, ol li') as $li) {
$ids[] = $li->id ?: $li->textContent;
}
var_dump($ids);
```
Resulted in this output:
```
array(3) { [0]=> string(2) "ab" [1]=> string(1) "x" [2]=> string(1)
"x" }
```
But I expected this output instead:
```
array(2) { [0]=> string(2) "ab" [1]=> string(1) "x" }
```
Element::querySelectorAll() behaves the same. Browsers return 2 elements.
### PHP Version
PHP 8.5.12
### Operating System
macOS