php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39760 cloning fails on nested SimpleXML-Object
Submitted: 2006-12-06 22:20 UTC Modified: 2006-12-30 15:43 UTC
From: saschagros at bluewin dot ch Assigned: helly (profile)
Status: Closed Package: SimpleXML related
PHP Version: 5.2.0 OS: Windows/Linux
Private report: No CVE-ID: None
 [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
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-30 15:43 UTC] rrichards@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 04:01:31 2024 UTC