ID:               46047
 Updated by:       [EMAIL PROTECTED]
 Reported By:      dalef at yahoo-inc dot com
-Status:           Open
+Status:           Closed
 Bug Type:         SimpleXML related
 Operating System: FreeBSD 4
 PHP Version:      5.2CVS-2008-09-10 (snap)
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------

[2008-09-10 21:37:09] dalef at yahoo-inc dot com

Description:
------------
When I run the following script I get strange results that are
difficult to test against, and when converted to json, a real pain to
use on the client-side.

<?php
    $xml = new
SimpleXMLElement('<foo><bar><![CDATA[]]></bar><baz/></foo>',
LIBXML_NOCDATA);
    print_r($xml);
    $json = json_encode($xml);
    echo "{$json}\n";
?>

Since bar is empty (Even though it has a CDATA tag that is removed)
before it gets to me ... I should get something like this
bar => ""
OR
at most ...
bar => SimpleXMLElemebt object ()

but ... what I don't expect is this:

SimpleXMLElement Object
(
    [bar] => SimpleXMLElement Object
        (
            [0] => 
        )
...

When this data is converted to json ... I get bar:{"0":""} which
requires me to do typeof and other types of tests on the client-side.

I mentioned this issue to our resident FE PHP expert here at Y! and
they said to file a bug.



Reproduce code:
---------------
Run this script on the command line:

<?php
    $xml = new
SimpleXMLElement('<foo><bar><![CDATA[]]></bar><baz/></foo>',
LIBXML_NOCDATA);
    print_r($xml);
    $json = json_encode($xml);
    echo "{$json}\n";
?>

Expected result:
----------------
SimpleXMLElement Object
(
    [bar] => ""
)

OR 

SimpleXMLElement Object
(
    [bar] => SimpleXMLElement Object
    (
    )
)

Actual result:
--------------
SimpleXMLElement Object
(
    [bar] => SimpleXMLElement Object
    (
        [0] => ""
    )
)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=46047&edit=1

Reply via email to