|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-07-21 12:23 UTC] rrichards@php.net
[2004-10-22 12:56 UTC] Jason at amp-design dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 15:00:02 2025 UTC |
Description: ------------ When using the itterator DomNode::childNodes to cycle through nodes objects that have been extended though PHP (In this case, TplTagDefault), the behaviour becomes inconsistent. As you can see from the output, the object returned is sometimes a TplTagDefault but other times it's a DOM* object. Generally the last item in the DomNodeList is of the correct type. I have posted this on a couple of forums/IRC support places and they all seem to agree it's a bug (though few people seem to have DOM/XML understanding). If this is not a bug, please could someone explain how I prevent objects from lossing their inheritance (i.e. prevent upcasting) when cycling through them. -- Jay Reproduce code: --------------- <?php class TplCompileTree extends DomDocument {} class TplTagDefault extends DomElement {} $docRoot = &new TplCompileTree(); $newNode = &new TplTagDefault('Root'); $docRoot->appendChild($newNode); for($i = 0; $i < 3; $i++) { $newNode->appendChild(new TplTagDefault('Kiddy'.$i)); } foreach($docRoot->childNodes AS $child) { var_dump($child); foreach($child->childNodes as $kids) { var_dump($kids); } } echo $docRoot->saveXML(); ?> Expected result: ---------------- object(TplTagDefault)#13 (0) { } object(TplTagDefault)#18 (0) { } object(TplTagDefault)#20 (0) { } object(TplTagDefault)#14 (0) { } <?xml version="1.0"?> <Root><Kiddy0/><Kiddy1/><Kiddy2/></Root> Actual result: -------------- object(TplTagDefault)#13 (0) { } object(DOMElement)#18 (0) { } object(DOMElement)#20 (0) { } object(TplTagDefault)#14 (0) { } <?xml version="1.0"?> <Root><Kiddy0/><Kiddy1/><Kiddy2/></Root>