php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36917 simplexml_load_file throws multiple errors making track_errors ineffective
Submitted: 2006-03-30 00:29 UTC Modified: 2006-03-30 01:36 UTC
From: php at xmlnode dot com Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.1.2 OS: Debian
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: php at xmlnode dot com
New email:
PHP Version: OS:

 

 [2006-03-30 00:29 UTC] php at xmlnode dot com
Description:
------------
when simplexml_load_file fails (because the target xml file is empty for example) there are multiple, basically useless, errors reported that makes track_errors and $php_errormsg ineffective

My workaround has been to load the file using dom and grab it's relevant error message then use interop to switch to simple if everything is ok... definitely sub-optimal.

Reproduce code:
---------------
<?php
//the easiest test is to create an empty file called empty.xml

error_reporting(2047);
ini_set('display_errors',0);
ini_set('track_errors',1);

if( ! $x = simplexml_load_file('empty.xml') ){
        echo $php_errormsg;
}
?>

Expected result:
----------------
either:

"empty.xml:1: parser error : Document is empty"

or:

"empty.xml:1: parser error : Start tag expected, '<' not found"

Actual result:
--------------
"^"

If you enable display_errors you'll see that there are 3 warnings for each 'error' ("Document is empty" and "Start tag expected")  There's the relevant error, then an empty error message and then the last one where the message is just "^" and because that's the last one, that's the one stored in $php_errormsg.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-30 01:36 UTC] bjori@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

libxml_use_internal_errors(true);
var_dump(libxml_get_last_error());
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Dec 06 17:05:53 2022 UTC