[php-src] Issue #11463: DOMChildNode::replaceWith() throws a DOM_NOT_FOUND_ERR if the node is preceded by a text node
| From: | JoshyPHP | Date: | Fri, 16 Jun 2023 15:34:13 +0000 |
| Subject: | [php-src] Issue #11463: DOMChildNode::replaceWith() throws a DOM_NOT_FOUND_ERR if the node is preceded by a text node | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244710@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11463
Author: JoshyPHP
### Description
The issue started between PHP 8.2.5 and PHP 8.2.6. Using
DOMChildNode::replaceWith() on
a node that is preceded by a text node results in a DOM_NOT_FOUND_ERR exception. The
error does not occur if the first text node is removed, or if DOMNode::replaceChild()
is used instead.
The following code:
```php
<?php declare(strict_types=1);
$dom = new DOMDocument;
$dom->loadXML('<r>..<X/>..</r>');
$el = $dom->createElement('Z');
$dom->getElementsByTagName('X')->item(0)->replaceWith($el);
die($dom->saveXML());
```
Resulted in this output:
```
Fatal error: Uncaught DOMException: Not Found Error in /tmp/file.php:7
Stack trace:
#0 /tmp/file.php(7): DOMElement->replaceWith(Object(DOMElement))
#1 {main}
thrown in /tmp/file.php on line 7
```
But I expected this output instead:
```
<?xml version="1.0"?>
<r>..<Z/>..</r>
```
### PHP Version
PHP 8.2.7
### Operating System
_No response_