php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46968 Extending SimplXMLElement (or Iterator) w/ __toString
Submitted: 2008-12-30 00:46 UTC Modified: 2009-07-24 16:44 UTC
Votes:3
Avg. Score:3.7 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: jordan dot raub at dataxltd dot com Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
16 + 6 = ?
Subscribe to this entry?

 
 [2008-12-30 00:46 UTC] 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>
|


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-21 07:05 UTC] dypa at bk dot ru
5.2.8 Windows NT DYPA 5.1 build 2600
Reproduced:
||
||
|<?xml version="1.0"?>
<foo>
  <bar/>
</foo>
|
 [2009-04-24 17:38 UTC] jani@php.net
See also bug #48059
 [2009-04-30 16:58 UTC] ludicruz at yahoo dot com
Confirmed w/ 5.3.0RC1
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 00:01:28 2024 UTC