<?php
$sample = new SimpleXMLElement('<root><parent><child1></child1></parent></root>');
$node = $sample->xpath('//parent');
$node[0]->addChild('child2');
echo LIBXML_DOTTED_VERSION, PHP_EOL, f($sample);
function f(SimpleXMLElement $x) {
$doc = dom_import_simplexml($x)->ownerDocument;
$doc->formatOutput = true;
return $doc->saveXML();
}
- Output for 5.5.36 - 5.5.37, 5.6.22 - 5.6.28, 7.0.7 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.13
- 2.9.4
<?xml version="1.0"?>
<root>
<parent>
<child1/>
<child2/>
</parent>
</root>
- Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.21, 7.0.0 - 7.0.6
- 2.9.3
<?xml version="1.0"?>
<root>
<parent>
<child1/>
<child2/>
</parent>
</root>
- Output for 5.4.0 - 5.4.45
- 2.9.2
<?xml version="1.0"?>
<root>
<parent>
<child1/>
<child2/>
</parent>
</root>
- Output for 5.3.25 - 5.3.29
- 2.9.1
<?xml version="1.0"?>
<root>
<parent>
<child1/>
<child2/>
</parent>
</root>
- Output for 5.3.15 - 5.3.24
- 2.8.0
<?xml version="1.0"?>
<root>
<parent>
<child1/>
<child2/>
</parent>
</root>
- Output for 5.1.3 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.14
- 2.7.8
<?xml version="1.0"?>
<root>
<parent>
<child1/>
<child2/>
</parent>
</root>
- Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.2
- Fatal error: Call to undefined method SimpleXMLElement::addChild() in /in/CueSv on line 6
Process exited with code 255. - Output for 4.4.2 - 4.4.9
- Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/CueSv on line 10
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
- Parse error: parse error, unexpected T_STRING, expecting ')' in /in/CueSv on line 10
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error, expecting `')'' in /in/CueSv on line 10
Process exited with code 255.
preferences:
99.26 ms | 418 KiB | 5 Q