|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-07-15 12:49 UTC] stefan dot priebsch at e-novative dot de
Description: ------------ The manual entry for json_encode() says the function works on any type except a resource. This is not accurate. json_encode() does not work properly on SimpleXML data that contains CDATA (see bug#41976). Documentation should be changed to reflect this. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 06:00:01 2025 UTC |
Anthony, I am terribly sorry, but I completely fail to see your point. What is the difference between an object and its data? An object is code+data, and I am sure that we'll agree that no code will ever be serialized or show up when something is cast to string. Besides, look at more complex examples: They work fine when *not* cast to string. When casting to string, json_encode() does not work at all. When json_encoding a complex XML structure, however, CDATA still does not show up - this is a bug. Example: $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</another><path><to><tag>something</tag></to></path></test>'); var_dump(json_encode($xml)); var_dump(json_encode((string) $xml)); So the situation is: you are telling me to cast to string before encoding. This works on "primitive" XML, but not on real one with nested tags. Encoding nested tags works fine if not casting to string, though, except for the fact that CDATA does not show up.