[php-src] Issue #20281: \Dom\Document::getElementById() is inconsistent after nodes are removed
| From: | cscott | Date: | Fri, 24 Oct 2025 16:02:54 +0000 |
| Subject: | [php-src] Issue #20281: \Dom\Document::getElementById() is inconsistent after nodes are removed | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-251112@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/20281
Author: cscott
### Description
The following code:
```php
<?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:
```
c
```
Compare to the following JS code in a browser:
```javascript
> 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
```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
_No response_