|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 23:00:01 2025 UTC |
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.