php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47734 simple_xml_load string fails without error message when encooding broken
Submitted: 2009-03-20 16:54 UTC Modified: 2009-04-09 01:00 UTC
Votes:5
Avg. Score:3.8 ± 1.0
Reproduced:3 of 4 (75.0%)
Same Version:2 (66.7%)
Same OS:0 (0.0%)
From: cupidle at gmx dot de Assigned:
Status: No Feedback Package: SimpleXML related
PHP Version: 5.2.9 OS: WinXP SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cupidle at gmx dot de
New email:
PHP Version: OS:

 

 [2009-03-20 16:54 UTC] cupidle at gmx dot de
Description:
------------
When simplexml_load_string fails loading xml it returns FALSE. 

An error message should be available via error_get_last. This is not the case when certain encoding errors are encountered.

Reproduce code:
---------------
I'm using this code to gracefully fall back on encoding errors:

    $xml = simplexml_load_string($data);

    // character encoding warning- hack
    if ($xml === false) 
    {
        $error = error_get_last();
     
        // this is nasty- sometimes simplexml_load_string fails but doesn't raise an error
#        if (eregi('simplexml_load_string', $error['message']))
        {
            $xml = simplexml_load_string(utf8_encode($data));
        }
    }


Expected result:
----------------
This does _sometimes_ work (i.e. call the innermost, encoded version), but not always. For example, simplexml_load_string silently fails without error message when processing data from amazon like this:

http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&Version=2007-12-24&Operation=ItemSearch&AssociateTag=cpuidle-20&AWSAccessKeyId=1CB01P12WQBRDNH10NR2&ItemPage=1&Keywords=Star+Wars%3A+Episode+1&

Actual result:
--------------
simplexml_load_string returns FALSE, but does not return error message.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-01 11:38 UTC] jani@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2009-04-09 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Oct 19 06:01:27 2019 UTC