#48059 [Opn->Bgs]: SimpleXmlElement __toString() not called on (string) cast
| From: | jani@php.net | Date: | Fri, 24 Apr 2009 17:37:57 +0000 |
| Subject: | #48059 [Opn->Bgs]: SimpleXmlElement __toString() not called on (string) cast | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-136213@lists.php.net to get a copy of this message | ||
ID: 48059
Updated by: jani@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] jani@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