From: jazzslider at gmail dot com Operating system: Linux PHP version: 5.2.0 PHP Bug Type: Feature/Change Request Bug description: Subclassed SimpleXMLElements with differently-subclassed child nodes
Description: ------------ I often use SimpleXML to provide a hierarchical organizational view of associated database records. For reference I have included some sample XML in the source code field. The Page element represents a record from a 'pages' table in the database; likewise, each Comment element represents an associated record in the 'comments' table. Sometimes, different types of data in my application require extra extensions to the SimpleXMLElement. This helps me get extra metadata or convenience features related to each content type. So, the Page object might need to be of class "PageInstance", which is itself a subclass of SimpleXMLElement. However, I'd like it if the associated Comment records contained within the PageInstance object could themselves be "CommentInstance" objects (another subclass of SimpleXMLElement). Reproduce code: --------------- <?php class PageInstance extends SimpleXMLElement { } class CommentInstance extends SimpleXMLElement { } $xml = '<Page><id>7</id><title>A Great Page</title><body>This is the body text of a great page.</body><Comment><page_id>7</page_id><user_id>12</user_id><body>Great job making this page!</body></Comment><Comment><page_id>7</page_id><user_id>15</user_id><body>I think this page is overrated.</body></Comment></Page>'; $sxe = simplexml_load_string($xml, 'PageInstance'); // Additional code making it possible to assign different // subclasses to children of $sxe (this is not currently // possible) echo get_class($sxe->Comment); ?> Expected result: ---------------- (Note that the following result is desired, but given the way SimpleXML currently works, it is not expected) ---------------------------------------------- CommentInstance Actual result: -------------- PageInstance -- Edit bug report at http://bugs.php.net/?id=40388&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40388&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40388&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40388&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=40388&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=40388&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=40388&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=40388&r=needscript Try newer version: http://bugs.php.net/fix.php?id=40388&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=40388&r=support Expected behavior: http://bugs.php.net/fix.php?id=40388&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=40388&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=40388&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=40388&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40388&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=40388&r=dst IIS Stability: http://bugs.php.net/fix.php?id=40388&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=40388&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=40388&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=40388&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=40388&r=mysqlcfg