|  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: 2021-11-21 11:55 UTC
From: jules dot bernable at gmail dot com Assigned:
Status: Open 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

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-21 11:55 UTC]
-PHP Version: 8.1.0RC6 +PHP Version: 8.0.0
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jan 19 21:03:36 2022 UTC