php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63575 Cloning are incorrect
Submitted: 2012-11-21 17:52 UTC Modified: 2017-10-24 07:02 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: vadimx at gmail dot com Assigned:
Status: Open Package: SimpleXML related
PHP Version: 5.3.18 OS: Windows/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vadimx at gmail dot com
New email:
PHP Version: OS:

 

 [2012-11-21 17:52 UTC] vadimx at gmail dot com
Description:
------------
When changing child's in cloned object, it's change in parent object, not in 
cloned.

Test script:
---------------
$xml = '<a><b></b></a>';

$o1 = new SimpleXMlElement($xml);
$o2 = clone $o1;

$r = current($o2->xpath('/a'));
$r->addChild('c',new SimpleXMlElement('<c></c>'));

echo $o1->asXML();
echo PHP_EOL;
echo $o2->asXML();

Expected result:
----------------
<?xml version="1.0"?>
<a><b/></a>

<a><b/><c></c></a>

Actual result:
--------------
<?xml version="1.0"?>
<a><b/><c></c></a>

<a><b/></a>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-24 15:55 UTC] laruence@php.net
-Assigned To: +Assigned To: helly
 [2012-11-24 15:55 UTC] laruence@php.net
helly, do you have time to look at this?
 [2017-10-24 07:02 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: helly +Assigned To:
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Sep 21 19:01:26 2019 UTC