Doc #53890 [Bgs]: DOMDocumentFragment and AppendChild

From: Date: Fri, 11 Feb 2011 13:19:37 +0000
Subject: Doc #53890 [Bgs]: DOMDocumentFragment and AppendChild
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5975@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53890&edit=1 ID: 53890 User updated by: giosh94mhz at gmail dot com Reported by: giosh94mhz at gmail dot com Summary: DOMDocumentFragment and AppendChild Status: Bogus Type: Documentation Problem Package: Documentation problem PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Correct. I know that appending a node to another node change parentNode reference. Anyway, DOMDocumentFragment is a "special" node; using $parent->appendChild($fragment); doesn't change the parent of fragment, but the parent of all the child nodes, so it is equivalent to: foreach( $fragment->childNodes as $child ) $parent->appendChild( $child ); So, "$fragment->childNodes->length" change after appending the fragment. This may seem obvious, but note that a DOMDocumentFragment is an instance of DOMNode: the user must be informed of that "unexpected" behaviour. Previous Comments: ------------------------------------------------------------------------ [2011-02-10 13:09:26] vrana@php.net Works as expected. The appendChild() method actually moves the node if it is already somewhere else. ------------------------------------------------------------------------ [2011-01-31 12:21:49] giosh94mhz at gmail dot com Description: ------------ --- From manual page: http://www.php.net/class.domdocumentfragment --- Undocumented behaviour for appendChild using a DOMDocumentFragment Test script: --------------- $doc=new DOMDocument(); $frag=$doc->createDocumentFragment(); $root=$doc->appendChild( $doc->createElement('root') ); $frag->appendChild( $doc->createElement('fragNode') ); echo $frag->childNodes->length; $root->appendChild($frag); echo $frag->childNodes->length; Expected result: ---------------- Documented behaviour. Actual result: -------------- 1 0 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53890&edit=1

« previous php.doc.bugs (#5975) next »