|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-04-21 07:05 UTC] dypa at bk dot ru
[2009-04-24 17:38 UTC] jani@php.net
[2009-04-30 16:58 UTC] ludicruz at yahoo dot com
[2009-07-24 16:44 UTC] jani@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 22:00:01 2025 UTC |
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> |