|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44814 cannot properly return DOMDocumentFragment
Submitted: 2008-04-24 04:11 UTC Modified: 2008-04-24 17:05 UTC
From: anthony at createvibe dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.5 OS: 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.
Block user comment
Status: Assign to:
Bug Type:
From: anthony at createvibe dot com
New email:
PHP Version: OS:


 [2008-04-24 04:11 UTC] anthony at createvibe dot com
When I create a document fragment via, DOMDocument::createDocumentFragment() and append child nodes to this fragment (not sure if the 2nd step is crucial to reproducing this bug), then try to return the document fragment and then try to append that fragment to another DOMDocument, I receive a DOMException / Wrong Document error.

Reproduce code:
function get_frag()
	$dom = new DOMDocument;
	$frag = $dom->createDocumentFragment();
	$frag->appendChild( $dom->createElement('br') );
	return( $frag );
$dom = new DOMDocument;
$dom->appendChild( get_frag() );
echo $dom->saveXML();

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

Actual result:
( ! ) DOMException: Wrong Document Error in ... test_bug.php on line 10
Call Stack
#	Time	Memory	Function	Location
1	0.0004	62056	{main}( )	../test_bug.php:0
2	0.0006	63780	DOMNode->appendChild( class DOMDocumentFragment { } )	../test_bug.php:10



string '/test_bug.php' (length=13)

Variables in local scope (#1)

$dom =




Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-24 12:32 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

You need to import every node, if you want to use it in another 

$dom->appendChild( $dom->importNode(get_frag(),true) );

works in your example
 [2008-04-24 17:05 UTC] anthony at createvibe dot com
Thank you!  I tried to importNode in my application, but not in my example.  The importNode didn't work for some reason, but seeing that it does work in my small example, I'll figure it out from there.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 02:01:23 2020 UTC