[php-src] Issue #11682: Consecutive calls to `DOMNode::before` and `DOMNode::remove` unlink wrong nodes

From: Date: Tue, 11 Jul 2023 21:01:33 +0000
Subject: [php-src] Issue #11682: Consecutive calls to `DOMNode::before` and `DOMNode::remove` unlink wrong nodes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-244952@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11682 Author: theseer ### Description The following code: ```php <?php declare(strict_types = 1); $dom = new DOMDocument; $dom->loadXML('<?xml version="1.0" ?><root><node /></root>'); $list = [ $dom->createElement('foo1'), $dom->createElement('foo2'), $dom->createElement('foo3') ]; $node = $dom->getElementsByTagName('node')->item(0); $node->before(...$list); $node->remove(); echo $dom->saveXML(); ``` Resulted in this output: ```xml <?xml version="1.0"?> <root><foo1/></root> ``` But I expected this output instead: ```xml <?xml version="1.0"?> <root><foo1/><foo2/><foo3/></root> ``` Observations: - When the $node->before() call gets replaced by $node->after(), the code works as expected. - When the $node->remove() call is commented out, the result is as expected, as the below output shows - When PHP 8.0.29 is used, it works as expected - For the record: PHP 7.4 doesn't implement ::before, so it cannot be used Ouput with ::before and no ::remove: ```xml <?xml version="1.0"?> <root><foo1/><foo2/><foo3/><node/></root> ``` Ouput with ::after and no ::remove: ```xml <?xml version="1.0"?> <root><node/><foo1/><foo2/><foo3/></root> ``` ### PHP Version PHP 8.2.8 / PHP 8.1.21 / PHP 8.3.0-alpha3 ### Operating System Fedora Linux 38 x86_64

« previous php.bugs (#244952) next »