From: Operating system: Windows 7 PHP version: 5.3.3 Package: SimpleXML related Bug Type: Bug Bug description:dom_import_simplexml() doesn't work on newly created SimpleXMLElement nodes
Description: ------------ The problem is readily apparent when you run the test script. When SimpleXMLElement dynamically creates a child element, and you directly call a method on the child element, the $this context is apparently not a proper SimpleXMLElement, i.e. dom_import_simplexml() does not accept it as input. class MyXML extends SimpleXMLElement { public function cdata($text) { dom_import_simplexml($this); } } $xml = new MyXML('<foo/>'); $xml->three->cdata('Three'); Test script: --------------- <?php class MyXML extends SimpleXMLElement { public function cdata($text) { $node = dom_import_simplexml($this); $owner = $node->ownerDocument; $node->appendChild($owner->createCDATASection($text)); return $this; } } $xml = new MyXML('<foo/>'); // works $xml->one = 'One'; // also works $xml->two = ''; $xml->two->cdata('Two'); // doesn't work $xml->three->cdata('Three'); print $xml->asXML(); Expected result: ---------------- <?xml version="1.0"?> <foo><one>One</one><two><![CDATA[Two]]></two><three><![CDATA[Three]]></three></foo > Actual result: -------------- Warning: dom_import_simplexml(): Invalid Nodetype to import in C:\WWW\Work\WC\www\dom.php on line 5 Notice: Trying to get property of non-object in C:\WWW\Work\WC\www\dom.php on line 6 Fatal error: Call to a member function appendChild() on a non-object in C:\WWW\Work\WC\www\dom.php on line 7 -- Edit bug report at http://bugs.php.net/bug.php?id=52858&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52858&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52858&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52858&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52858&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52858&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52858&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52858&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52858&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52858&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52858&r=support Expected behavior: http://bugs.php.net/fix.php?id=52858&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52858&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52858&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52858&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52858&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52858&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52858&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52858&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52858&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52858&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52858&r=mysqlcfg