|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-04-24 17:37 UTC] jani@php.net
[2009-04-24 17:37 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 15:00:02 2025 UTC |
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