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: 2020-04-23 14:29 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: cmb (profile)
Status: Closed Package: SimpleXML related
PHP Version: 5.3.18 OS: Windows/Linux
Private report: No CVE-ID: None
 [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

Pull Requests

Pull requests:

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:
 [2020-04-23 14:28 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #63575: Root elements are not properly cloned
On GitHub:  https://github.com/php/php-src/pull/5438
Patch:      https://github.com/php/php-src/pull/5438.patch
 [2020-04-23 14:29 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2020-06-17 14:49 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3a0bdb720a9e54b91c812665f36b936e6cf44ef3
Log: Fix #63575: Root elements are not properly cloned
 [2020-06-17 14:49 UTC] cmb@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 09:01:28 2024 UTC