php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48511 libxml_get_errors() returns an empty array but libxml_get_last_error() doesn't
Submitted: 2009-06-09 17:49 UTC Modified: 2010-05-05 15:21 UTC
From: geoffers+phpbugs at gmail dot com Assigned: rrichards (profile)
Status: Not a bug Package: XML Writer
PHP Version: 5.3CVS-2009-06-09 (CVS) OS: Mac OS 10.5.7
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: geoffers+phpbugs at gmail dot com
New email:
PHP Version: OS:

 

 [2009-06-09 17:49 UTC] geoffers+phpbugs at gmail dot com
Description:
------------
I would expect the last member of the array returned by libxml_get_errors() to be equal to libxml_get_last_error(), but the former returns an empty array while the latter returns the expected error object.

Reproduce code:
---------------
<?php

$foo = new XMLWriter();
$foo->openMemory();
$foo->startElement("\xEF\xBF\xBF");
var_dump(libxml_get_last_error());
var_dump(libxml_get_errors());
var_dump(libxml_get_last_error() == end(libxml_get_errors()));

Expected result:
----------------
Warning: XMLWriter::startElement(): Char 0xFFFF out of allowed range in /Users/gsnedders/Desktop/test.php on line 5

Warning: XMLWriter::startElement(): Invalid Element Name in /Users/gsnedders/Desktop/test.php on line 5
object(LibXMLError)#2 (6) {
  ["level"]=>
  int(3)
  ["code"]=>
  int(9)
  ["column"]=>
  int(0)
  ["message"]=>
  string(33) "Char 0xFFFF out of allowed range
"
  ["file"]=>
  string(0) ""
  ["line"]=>
  int(0)
}
array(1) {
  [0]=>
  object(LibXMLError)#2 (6) {
    ["level"]=>
    int(3)
    ["code"]=>
    int(9)
    ["column"]=>
    int(0)
    ["message"]=>
    string(33) "Char 0xFFFF out of allowed range
"
    ["file"]=>
    string(0) ""
    ["line"]=>
    int(0)
  }
}
bool(true)

Actual result:
--------------
Warning: XMLWriter::startElement(): Char 0xFFFF out of allowed range in /Users/gsnedders/Desktop/test.php on line 5

Warning: XMLWriter::startElement(): Invalid Element Name in /Users/gsnedders/Desktop/test.php on line 5
object(LibXMLError)#2 (6) {
  ["level"]=>
  int(3)
  ["code"]=>
  int(9)
  ["column"]=>
  int(0)
  ["message"]=>
  string(33) "Char 0xFFFF out of allowed range
"
  ["file"]=>
  string(0) ""
  ["line"]=>
  int(0)
}
array(0) {
}
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-21 09:37 UTC] michael202 at gmx dot de
I have a similar problem:

libxml_get_errors() is empty after loading a faulty XML with
simplexml_load_file() BUT libxml_get_last_error() contains the last
error:
var_dump(libxml_get_errors()) ----> array(0) { }
var_dump(libxml_get_last_error()) ----> object(LibXMLError)#11 ....



"solution" is to use libxml_use_internal_errors:

libxml_clear_errors(); // otherwise you also get all of the old errors
libxml_use_internal_errors(true);

other advantage is the you do not get any PHP Warning outputs and you can call simplexml_load_file without the @-operator


strange though:
simplexml_load_file() displays the correct error position in the "PHP Warning" BUT libxml_get_errors() does not contain it.
 [2009-08-21 09:38 UTC] michael202 at gmx dot de
Oh I forgot to mention that the error is present in the release version of php 5.3:
PHP 5.3.0 (cli) (built: Jul 29 2009 15:03:42)
 [2010-05-05 15:21 UTC] rrichards@php.net
-Status: Assigned +Status: Bogus
 [2010-05-05 15:21 UTC] rrichards@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

You must set libxml_use_internal_errors(true); in order to to use the structured 
error handler and get a populated libxml_get_errors() return value. 
libxml_get_last_error() always will return last error regardless of the xml error 
handler used.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC