Description
The following code:
<?php
$d = \Dom\HTMLDocument::createFromString('<p id="a">b</p><p id="a">c</p>');
$p = $d->getElementById('a');
$p->remove();
echo($d->getElementById('a')->innerHTML);
Resulted in this output:
Attempt to read property "innerHTML" on null
But I expected this output instead:
Compare to the following JS code in a browser:
> document.body.innerHTML = '<p id=a>b</p><p id=a>c</p>'
'<p id=a>b</p><p id=a>c</p>'
> p = document.getElementById('a')
<p id="a">b</p>
> p.remove()
undefined
> document.getElementById('a').innerHTML
'c'
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
No response
Description
The following code:
Resulted in this output:
But I expected this output instead:
Compare to the following JS code in a browser:
PHP Version
Operating System
No response