|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-10-04 09:23 UTC] mike@php.net
[2013-10-04 09:23 UTC] mike@php.net
-Status: Open
+Status: Closed
[2014-10-07 23:17 UTC] stas@php.net
[2014-10-07 23:28 UTC] stas@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 19:00:01 2025 UTC |
Description: ------------ Hi! I would expect XML parsing errors to be suppressed when calling the XMLReader::xml() with the LIBXML_NOERROR and LIBXML_NOWARNING options passed. In addition, libxml_get_errors() also does not get populated with any xml errors regardless of the settings used. This makes it very hard to catch errors in an OOP-friendly way. The only true option to handle errors, is to use set_error_handler(), but this is a bad practice for libraries to use, as this modifies a global state. Using libxml_use_internal_errors(true); has no further effect. Test script: --------------- <?php $xml = <<<XML <?xml version="1.0"?> <rootElem> XML; libxml_use_internal_errors(true); $reader = new XMLReader(); $reader->xml($xml, null, LIBXML_NOERROR | LIBXML_NOWARNING); $reader->read(); print_r(libxml_get_errors()); Expected result: ---------------- No PHP errors thrown, and an error showing up in print_r Actual result: -------------- PHP Warning: XMLReader::read(): An Error Occured while reading in /Users/evert/code/xml/errortest.php on line 11 PHP Stack trace: PHP 1. {main}() /Users/evert/code/xml/errortest.php:0 PHP 2. XMLReader->read() /Users/evert/code/xml/errortest.php:11 Warning: XMLReader::read(): An Error Occured while reading in /Users/evert/code/xml/errortest.php on line 11 Call Stack: 0.0003 226624 1. {main}() /Users/evert/code/xml/errortest.php:0 0.0005 227616 2. XMLReader->read() /Users/evert/code/xml/errortest.php:11 Note that when the LIBXML constants, and libxml_use_internal_errors() are not used, a 4 distinct PHP warnings are thrown. This would suggest that libxml errors are indeed suppressed; but there's an error mechanism in XMLReader as well.