php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70570 json_encode ignores simplexml cdata
Submitted: 2015-09-24 10:17 UTC Modified: 2020-09-18 14:46 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: cph at osde dot uk Assigned:
Status: Verified Package: SimpleXML related
PHP Version: 5.5.29 OS: xubuntu 14
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cph at osde dot uk
New email:
PHP Version: OS:

 

 [2015-09-24 10:17 UTC] cph at osde dot uk
Description:
------------
json_encode ignores simplexml cdata fields and returns a blank string instead of cdata may be related to https://bugs.php.net/bug.php?id=54632&edit=2

Test script:
---------------
<?php

$s = <<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Errors>
	<Error>
	<ErrorId>XML999</ErrorId>
	<ErrorText><![CDATA[cvc-complex-type: Invalid content was found starting with XXX. One of '{XXX}' is expected.]]></ErrorText>
	</Error>
</Errors>
</Response>
EOT;

$xml = simplexml_load_string($s);

echo $xml->Errors->Error->ErrorId.PHP_EOL;
echo $xml->Errors->Error->ErrorText.PHP_EOL;

echo json_encode($xml,JSON_PRETTY_PRINT);


Expected result:
----------------
XML999
cvc-complex-type: Invalid content was found starting with XXX. One of '{XXX}' is expected.
{
    "Errors": {
        "Error": {
            "ErrorId": "XML999",
            "ErrorText": "cvc-complex-type: Invalid content was found starting with XXX. One of '{XXX}' is expected."
        }
    }
}

Actual result:
--------------
XML999
cvc-complex-type: Invalid content was found starting with XXX. One of '{XXX}' is expected.
{
    "Errors": {
        "Error": {
            "ErrorId": "XML999",
            "ErrorText": {

            }
        }
    }
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-07 16:05 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-08-07 16:05 UTC] cmb@php.net
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

See <http://php.net/manual/en/simplexmlelement.tostring.php>.
 [2018-08-07 17:38 UTC] cmb@php.net
-Status: Not a bug +Status: Re-Opened -Assigned To: cmb +Assigned To:
 [2018-08-07 17:38 UTC] cmb@php.net
> See <http://php.net/manual/en/simplexmlelement.tostring.php>.

Nonsense, sorry!  Re-opening.
 [2020-09-18 14:46 UTC] cmb@php.net
-Status: Re-Opened +Status: Verified
 [2020-09-18 14:46 UTC] cmb@php.net
This is not particularly related to json_encode(), though; cf.
<https://3v4l.org/l6Xmu>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 19:01:29 2024 UTC