note 95330 deleted from intro.simplexml by danbrown
| From: | danbrown@php.net | Date: | Mon, 28 Dec 2009 00:23:26 +0000 |
| Subject: | note 95330 deleted from intro.simplexml by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164369@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
Hi,
I have a question about simplexml and encoding and decoding a simplexml object. When I have an
empty node, it is turned into an empty simplexml element object when using simplexml. Empty nodes
should have a string length of zero, and empty simplexml element objects do indeed have a string
length of zero.
However, if I json encode and json decode the simplexml object, the empty node is turned into an
empty array through the json encoding and deoding, and whereas originally the node's string
length was zero and the string length of an empty simplexml element object is zero, after json
encoding and decoding the node is turned into an empty array with a string length of 5. Is there a
way to prevent empty nodes from turning into empty arrays when you json encode and json decode
simplexml objects?
Using just simplexml, print_r gives:
SimpleXMLElement Object ( [name] => James [id] => SimpleXMLElement Object ( )
strlen of the empty [id] simplexml element object is zero.
Using simplexml then json encoding and json decoding, print r gives:
Array ( [name] => James [id] => Array ( )
strlen of the empty [id] array is 5.
I don't want the empty simplexml object turned into an empty array...I want to be able to test
the strlen, and since it was an empty node to begin with after json encoding and decoding I want the
strlen to remain zero, not 5. Any suggestions? Is this a bug?