ID: 41976 User updated by: stefan dot priebsch at e-novative dot de -Summary: Seems to work on nested XML, but not with CDATA Reported By: stefan dot priebsch at e-novative dot de -Status: Bogus +Status: Open Bug Type: JSON related Operating System: WinXP PHP Version: 5.2.3 New Comment:
Johannes, would you please care to actually *read* and try to *understand* my bug report before marking it as bogus? My point is that json_encode() works properly with nested XML, but does NOT work correctly when the nested XML contains CDATA. Previous Comments: ------------------------------------------------------------------------ [2007-07-17 12:36:14] [EMAIL PROTECTED] $xml and (string)$xml are different things. Using different things as arguments for a function gives different results. ------------------------------------------------------------------------ [2007-07-17 10:46:38] stefan dot priebsch at e-novative dot de I re-opened the bug due to the discussion of bug #42001. json_encode() does not work on nested XML with a string cast, but it does work without a string cast. (Of course except for the CDATA problem that made me file this bug in the first place.) $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><test><sub>test</sub><another>value</another><path><to ><tag>something</tag></to></path></test>'); var_dump(json_encode($xml)); var_dump(json_encode((string) $xml)); $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><test><sub><![CDATA[test]]></sub><another>value</anoth er><path><to><tag>something</tag></to></path></test>'); var_dump(json_encode($xml)); var_dump(json_encode((string) $xml)); ------------------------------------------------------------------------ [2007-07-13 08:08:02] [EMAIL PROTECTED] Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Yes, and it will try to serialize the SimpleXML object, what won't work, that's part of SimpleXML's behaviour ------------------------------------------------------------------------ [2007-07-13 06:33:16] stefan dot priebsch at e-novative dot de Sorry, I disagree. This is a bug, not bogus. The manual says that json_encode works on any type except resources. $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><test><![CDATA[test]]></test>'); var_dump(is_resource($xml)); outputs false, (which is obvious as SimpleXML is not listed in the list of resource types). Thus SimpleXML is not a resource and must be processed by json_encode() without a string cast. How would I supposed to cast an XML tree to string anyway? Please have a look at bug#38680, where a similar issue was discussed. ------------------------------------------------------------------------ [2007-07-12 09:08:39] [EMAIL PROTECTED] var_dump((string) $xml); var_dump(json_encode($xml)); <-- you have to cast it to string explicitly, otherwise json_encode() will encode the object itself, not it's string representation. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/41976 -- Edit this bug report at http://bugs.php.net/?id=41976&edit=1