|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-01-31 12:21 UTC] 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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 02:00:02 2025 UTC |
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.