php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80063 XMLReader not suppressing warnings
Submitted: 2020-09-05 10:50 UTC Modified: 2021-04-01 12:08 UTC
From: pmishev at gmail dot com Assigned:
Status: Open Package: XML Reader
PHP Version: 7.3.22 OS: Ubuntu 18.04
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: pmishev at gmail dot com
New email:
PHP Version: OS:

 

 [2020-09-05 10:50 UTC] pmishev at gmail dot com
Description:
------------
Warnings when opening an non-existing XML file are not being suppressed.

Neither libxml_use_internal_errors(true), nor setting LIBXML_NOERROR | LIBXML_NOWARNING has any effect whatsoever.

The problem seems related to https://bugs.php.net/bug.php?id=64230

Test script:
---------------
<?php

$xml = 'compress.zlib://inexisting_file.xml.gz';

libxml_use_internal_errors(true);

$reader = new XMLReader();
$reader->open($xml, null, LIBXML_NOERROR | LIBXML_NOWARNING);

$reader->read();

print_r(libxml_get_errors());


Expected result:
----------------
No PHP warnings thrown, and an error showing up in print_r


Actual result:
--------------
PHP Warning:  XMLReader::open(compress.zlib://inexisting_file.xml.gz): failed to open stream: operation failed in test.php on line 8
PHP Warning:  XMLReader::open(): Unable to open source data in test.php on line 8
PHP Warning:  XMLReader::read(): Load Data before trying to read in test.php on line 10
Array
(
)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-01 11:31 UTC] cmb@php.net
-Status: Open +Status: Analyzed -Assigned To: +Assigned To: cmb
 [2021-04-01 11:31 UTC] cmb@php.net
The first warning isn't a libxml error, but rather comes from
PHP's stream layer; as such, it is unsuitable to treat it as
libxml error.

The second warning is indeed unnecessary noise (quite similar to
bug #64230).

The third warning is correct; you should make sure to check the
return value of XMLReader::open() before you proceed.
 [2021-04-01 12:08 UTC] cmb@php.net
-Status: Analyzed +Status: Open -Assigned To: cmb +Assigned To:
 [2021-04-01 12:08 UTC] cmb@php.net
Sigh, it's actually more complex than I thought.  If the given
protocol is statable, a silent stat is executed, and if that
fails, no attempt is made to try to open the file.  In this case
the second warning is important information.  Only if the protocol
is not statable (like compress.zlib://), there are two warnings.
Not sure what to do about that.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 04:03:37 2021 UTC