note 95330 added to intro.simplexml
| From: | Anonymous at osu1 dot php dot net | Date: | Sun, 27 Dec 2009 21:20:28 +0000 |
| Subject: | note 95330 added to intro.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164367@lists.php.net to get a copy of this message | ||
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?
----
Server IP: 64.71.164.2
Probable Submitter: 71.82.80.77
----
Manual Page -- http://www.php.net/manual/en/intro.simplexml.php
Edit -- https://master.php.net/note/edit/95330
Del: integrated -- https://master.php.net/note/delete/95330/integrated
Del: useless -- https://master.php.net/note/delete/95330/useless
Del: bad code -- https://master.php.net/note/delete/95330/bad+code
Del: spam -- https://master.php.net/note/delete/95330/spam
Del: non-english -- https://master.php.net/note/delete/95330/non-english
Del: in docs -- https://master.php.net/note/delete/95330/in+docs
Del: other reasons-- https://master.php.net/note/delete/95330
Reject -- https://master.php.net/note/reject/95330
Search -- https://master.php.net/manage/user-notes.php