php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64230 XMLReader does not suppress errors.
Submitted: 2013-02-18 00:44 UTC Modified: 2013-02-18 05:46 UTC
Votes:4
Avg. Score:4.5 ± 0.9
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:0 (0.0%)
From: evert at rooftopsolutions dot nl Assigned:
Status: Closed Package: XML Reader
PHP Version: 5.4.11 OS: OS X 10.8
Private report: No CVE-ID: None
 [2013-02-18 00:44 UTC] evert at rooftopsolutions dot nl
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.



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-04 09:23 UTC] mike@php.net
Automatic comment on behalf of mike
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f6ff3a28d60c24dea2a05344d9b7eb823f09b4e5
Log: Fixed bug #64230 (XMLReader does not suppress errors)
 [2013-10-04 09:23 UTC] mike@php.net
-Status: Open +Status: Closed
 [2014-10-07 23:17 UTC] stas@php.net
Automatic comment on behalf of mike
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=f6ff3a28d60c24dea2a05344d9b7eb823f09b4e5
Log: Fixed bug #64230 (XMLReader does not suppress errors)
 [2014-10-07 23:28 UTC] stas@php.net
Automatic comment on behalf of mike
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=f6ff3a28d60c24dea2a05344d9b7eb823f09b4e5
Log: Fixed bug #64230 (XMLReader does not suppress errors)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC