cloning fails on nested SimpleXML-Object
[2006-12-06 22:20 UTC] saschagros at bluewin dot ch
Description:
------------
"clone $simpleXML->subElement1->subElement2" does not work as excepted.
It does not return a clone of itself but a clone of it's parent.
Tested on:
Windows with PHP 5.2.0
Linux with PHP 5.2.0
Linux with PHP 5.0.4
Reproduce code:
---------------
$xml = '<?xml version="1.0" ?>
<test>
<level1>
<level2a>text1</level2a>
<level2b>text2</level2b>
</level1>
</test>';
$test = simplexml_load_string($xml);
print_r($test->level1->level2a);
$test2 = clone $test;
print_r($test2->level1->level2a);
$test3 = clone $test->level1->level2a;
print_r($test3);
Expected result:
----------------
SimpleXMLElement Object
(
[0] => text1
)
SimpleXMLElement Object
(
[0] => text1
)
SimpleXMLElement Object
(
[0] => text1
)
Actual result:
--------------
SimpleXMLElement Object
(
[0] => text1
)
SimpleXMLElement Object
(
[0] => text1
)
SimpleXMLElement Object
(
[level2a] => text1
[level2b] => text2
)