|  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.
Block user comment
Status: Assign to:
Bug Type:
From: php at xmlnode dot com
New email:
PHP Version: OS:


 [2006-03-30 00:29 UTC] php at xmlnode dot com
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:
//the easiest test is to create an empty file called empty.xml


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

Expected result:

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


"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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-30 01:36 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 19:01:33 2024 UTC