#46968 [Com]: Extending SimplXMLElement (or Iterator) w/ __toString
| From: | ludicruz at yahoo dot com | Date: | Thu, 30 Apr 2009 16:58:27 +0000 |
| Subject: | #46968 [Com]: Extending SimplXMLElement (or Iterator) w/ __toString | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-136586@lists.php.net to get a copy of this message | ||
ID: 46968
Comment by: ludicruz at yahoo dot com
Reported By: jordan dot raub at dataxltd dot com
Status: Open
Bug Type: SimpleXML related
Operating System: *
PHP Version: 5.2.9
New Comment:
Confirmed w/ 5.3.0RC1
Previous Comments:
------------------------------------------------------------------------
[2009-04-24 17:38:24] jani@php.net
See also bug #48059
------------------------------------------------------------------------
[2009-04-21 07:05:59] dypa at bk dot ru
5.2.8 Windows NT DYPA 5.1 build 2600
Reproduced:
||
||
|<?xml version="1.0"?>
<foo>
<bar/>
</foo>
|
------------------------------------------------------------------------
[2008-12-30 00:46:14] jordan dot raub at dataxltd dot com
Description:
------------
implicit call to __toString() for the extended class does not work
properly an empty value is returned (even without the try catch block
nothing is returned)
Reproduce code:
---------------
<?php
class XML extends SimpleXMLElement
{
public function __toString()
{
try
{
$xml = new DOMDocument('1.0', 'utf-8');
$xml->formatOutput = TRUE;
$xml->preserveWhiteSpace = FALSE;
$xml->loadXML($this->asXML());
$retval = $xml->saveXML();
}
catch(Exception $e)
{
$retval = '';
}
return $retval;
}
}
$xml = new XML('<foo><bar/></foo>');
echo '|' . $xml . "|\n";
echo '|' . (string) $xml . "|\n";
echo '|' . $xml->__toString() . "|\n";
Expected result:
----------------
|<?xml version="1.0"?>
<foo>
<bar/>
</foo>
|
|<?xml version="1.0"?>
<foo>
<bar/>
</foo>
|
|<?xml version="1.0"?>
<foo>
<bar/>
</foo>
|
Actual result:
--------------
||
||
|<?xml version="1.0"?>
<foo>
<bar/>
</foo>
|
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46968&edit=1