ID: 29092 Updated by: [EMAIL PROTECTED] Reported By: Jason at hybd dot net -Status: Open +Status: Bogus Bug Type: *XML functions Operating System: Windows 2003 Enterprise Server PHP Version: 5.0.0RC3 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Better memory management was more important than this. The objects are limited to scope and since you cannot cast objects, you would need to persist the newly created objects objects in some way. i.e.: <?php class TplCompileTree extends DomDocument {} class TplTagDefault extends DomElement {} $docRoot = &new TplCompileTree(); $newNode = &new TplTagDefault('Root'); $docRoot->appendChild($newNode); $doc_array = array(); for($i = 0; $i < 3; $i++) { $doc_array[] = $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(); ?> Previous Comments: ------------------------------------------------------------------------ [2004-07-11 14:28:44] Jason at hybd dot net 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> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29092&edit=1