Closed
Description
Description
The following code:
<?php
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
$doc->loadXML(
<<<EOXML
<x>
<item1 />
<item2 />
<item3 />
<item4 />
<item5 />
</x>
EOXML
);
foreach ($doc->documentElement->childNodes as $i => $node) {
echo $node->localName . PHP_EOL;
if ($i === 2) {
$node->remove();
}
}
Resulted in this output:
item1
item2
item3
But I expected this output instead:
item1
item2
item3
item5
Source: nielsdos#93 (comment)
Credits to @veewee. Similar issue exists for attributes.
PHP Version
Since always
Operating System
No response