Bug #48511 [Asn->Bgs]: libxml_get_errors() returns an empty array but libxml_get_last_error() doesn't

From: Date: Wed, 05 May 2010 13:21:52 +0000
Subject: Bug #48511 [Asn->Bgs]: libxml_get_errors() returns an empty array but libxml_get_last_error() doesn't
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-150196@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=48511&edit=1

 ID:               48511
 Updated by:       rrichards@php.net
 Reported by:      geoffers+phpbugs at gmail dot com
 Summary:          libxml_get_errors() returns an empty array but
                   libxml_get_last_error() doesn't
-Status:           Assigned
+Status:           Bogus
 Type:             Bug
 Package:          XML Writer
 Operating System: Mac OS 10.5.7
 PHP Version:      5.3CVS-2009-06-09 (CVS)
 Assigned To:      rrichards

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2009-08-21 09:38:58] 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)

------------------------------------------------------------------------
[2009-08-21 09:37:18] 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-06-09 17:49:07] 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)


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=48511&edit=1


Thread (5 messages)

« previous php.bugs (#150196) next »