From: Jason at hybd dot net Operating system: Windows 2003 Enterprise Server PHP version: 5.0.0RC3 PHP Bug Type: *XML functions Bug description: Object Upcasting Occurs upon itterating children
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 bug report at http://bugs.php.net/?id=29092&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29092&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=29092&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=29092&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=29092&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=29092&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=29092&r=needscript Try newer version: http://bugs.php.net/fix.php?id=29092&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=29092&r=support Expected behavior: http://bugs.php.net/fix.php?id=29092&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=29092&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=29092&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=29092&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29092&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=29092&r=dst IIS Stability: http://bugs.php.net/fix.php?id=29092&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=29092&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=29092&r=float