|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81642 DOMChildNode::replaceWith() bug when replacing a node with itself.
Submitted: 2021-11-19 16:51 UTC Modified: 2022-04-25 12:59 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jules dot bernable at gmail dot com Assigned: beberlei (profile)
Status: Verified Package: DOM XML related
PHP Version: 8.0.0 OS: debian unstable
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-11-19 16:51 UTC] jules dot bernable at gmail dot com
When calling `DOMChildNode::replaceWith()` on a given node,
If the node is also part of the argument list, PHP either throws a DOMException or just hangs indefinitely.

The bug is present at least in versions 8.0.12 and 8.1.0RC6

Test script:
// example 1
$doc = new DOMDocument();
$doc->appendChild($target = $doc->createElement('test'));
$target->replaceWith($target); // PHP Fatal error:  Uncaught DOMException: Not Found Error

// example 2
$doc = new DOMDocument();
$doc->appendChild($target = $doc->createElement('test'));
$target->replaceWith($target, 'foo'); // program hangs indefinitely

Expected result:
Both examples should be handled correctly, like browsers do.


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-21 11:55 UTC]
-PHP Version: 8.1.0RC6 +PHP Version: 8.0.0
 [2022-04-25 12:59 UTC]
-Status: Open +Status: Verified -Assigned To: +Assigned To: beberlei
 [2022-04-25 12:59 UTC]
I can confirm the reported issues.

Benjamin, could you have a look at this?
 [2022-06-10 09:22 UTC] afshin dot meh at gmail dot com
I'm happy to look into this as well if it's not being worked on yet?
 [2022-09-13 18:14 UTC] stri73971 at gmail dot com
The following pull request has been associated:

Patch Name: Fixed and simplified array_replace description
On GitHub:
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Oct 01 21:05:52 2022 UTC