ID: 48059 Updated by: j...@php.net Reported By: doctorrock83 at gmail dot com -Status: Open +Status: Bogus Bug Type: SimpleXML related Operating System: Win32 PHP Version: 5.2.9 New Comment:
Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely to be the same. Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2009-04-24 17:37:51] j...@php.net See bug #46968 ------------------------------------------------------------------------ [2009-04-23 09:27:08] doctorrock83 at gmail dot com Description: ------------ If I extend SimpleXmlElement and add a __toString() method to it, that method is not called when I cast my object using (string)$obj. It is used however on implicit casts (e.g echo $sxmlObj) Reproduce code: --------------- class MyXml extends SimpleXMLElement { public function __toString() { return $this->asXML(); } public function export() { return (string)$this; } } $xml = new MyXml("<xml><some>xml</some></xml>"); echo $xml; // 1 $a = (string)$xml; echo $a; // 2 echo $xml->export(); // 3 Expected result: ---------------- 1 : xml returned 2 : xml returned 3: xml returned Actual result: -------------- 1 : OK 2: nothing is returned 3: nothing is returned ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48059&edit=1