Note that DOMDocumentFragment is a bit special when it's added to another node. When that happens, not the fragment itself is added as a child, but all of the children of the fragment are moved over to the new parent node.
For example, consider this script:
<?php
$doc = new DOMDocument();
$fragment = $doc->createDocumentFragment();
$fragment->appendChild($doc->createElement('foo'));
var_dump($fragment->firstChild);
$doc->appendChild($fragment);
var_dump($fragment->firstChild);
var_dump($doc->childNodes->length);
var_dump($doc->firstChild);
?>
This produces the following output:
object(DOMElement)#3 (0) {
}
NULL
int(1)
object(DOMElement)#3 (0) {
}