Skip to content

\Dom\HTMLDocument querySelectorAll selecting only the first when using ~ and :has #18877

Closed

Description

@momala454

Description

The following code:

<?php

$text = <<<TEXT
<html>
<head>
</head>
<body>
    <div><div></div></div>
    <span></span>
    <span></span>
    <span></span>
</body>
</html>
TEXT;

$dom = \Dom\HTMLDocument::createFromString($text, options: LIBXML_NOERROR);
var_dump($dom->querySelectorAll('div:has(div) ~ *'));

Resulted in this output:

object(Dom\NodeList)#3 (1) {
  ["length"]=>
  int(1)
}

But I expected this output instead:

object(Dom\NodeList)#3 (1) {
  ["length"]=>
  int(3)
}

PHP Version

PHP 8.4.8 (cli) (built: Jun 11 2025 00:01:02) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.8, Copyright (c) Zend Technologies

Operating System

No response

Activity

  1. ndossche commented on Jun 19, 2025

    @ndossche
    Member

    You're right.
    This appears to be an upstream issue, same as lexbor/lexbor#279.

  2. added a commit that references this issue on Jul 18, 2025
    f884916
  3. ndossche commented on Aug 10, 2025

    @ndossche
    Member

    I've merged the fix into master and will backport if no problems arise.

  4. added a commit that references this issue on Aug 10, 2025
    aecf2a6
  5. ndossche commented on Aug 24, 2025

    @ndossche
    Member

    This is backported now too to PHP 8.4.13 which should appear in September.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions