|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37277 cloning Dom Documents or Nodes does not work
Submitted: 2006-05-02 15:04 UTC Modified: 2006-05-03 08:45 UTC
From: frank at cleverbridge dot com Assigned: rrichards (profile)
Status: Closed Package: DOM XML related
PHP Version: 5.1.3 OS: Linux 2.6.12-1.1381_FC3 i686 ath
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.
Block user comment
Status: Assign to:
Bug Type:
From: frank at cleverbridge dot com
New email:
PHP Version: OS:


 [2006-05-02 15:04 UTC] frank at cleverbridge dot com
Since 5.1.3 you cannot copy a dom object. References still work. The implementation of the xml extension seam to have changed.

Reproduce code:
Since 5.1.3 the following code does not work anymore:


$dom1 = new DomDocument('1.0', 'UTF-8');

$xml = '<foo />';

print "<xmp>\n".$dom1->saveXML()."</xmp>\n";

$node = clone $dom1->documentElement;

$dom2 = new DomDocument('1.0', 'UTF-8');
$dom2->appendChild($dom2->importNode($node->cloneNode(true), TRUE));

print "<xmp>\n".$dom2->saveXML()."</xmp>\n";

$dom3 = clone $dom1;

print "<xmp>\n".$dom3->saveXML()."</xmp>\n";


Expected result:
<?xml version="1.0"?>

<?xml version="1.0"?>

<?xml version="1.0"?>

Actual result:
&lt;?xml version="1.0"?&gt; &lt;foo/&gt;
Warning: DOMNode::cloneNode() [function.DOMNode-cloneNode]: Couldn't fetch DOMElement in /www/content/
spielzeug/xslt/513.php on line 13

Warning: DOMDocument::importNode() expects parameter 1 to be DOMNode, null given in /www/content/
spielzeug/xslt/513.php on line 13

Warning: DOMNode::appendChild() expects parameter 1 to be DOMNode, null given in /www/content/
spielzeug/xslt/513.php on line 13
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
Warning: DOMDocument::saveXML() [function.DOMDocument-saveXML]: Couldn't fetch DOMDocument in /www/content/
spielzeug/xslt/513.php on line 19


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-02 20:32 UTC]
Fix is coming. Until then use the cloneNode() method instead of the clone keyword.
 [2006-05-03 08:45 UTC]
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
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC