|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74004 LIBXML_NOWARNING flag ingnored on loadHTML*
Submitted: 2017-01-26 21:35 UTC Modified: 2017-03-02 11:38 UTC
From: work at timothytown dot com Assigned: nikic (profile)
Status: Closed Package: DOM XML related
PHP Version: 7.1.1 OS: all
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.
Block user comment
Status: Assign to:
Bug Type:
From: work at timothytown dot com
New email:
PHP Version: OS:


 [2017-01-26 21:35 UTC] work at timothytown dot com
The source in the PHP dom extension causes the LIBXML_NOWARNING flag to be ignored when loading html through DOMDocument.

Problem is in ext/dom/document.c of PHP source, in the dom_load_html method. 
Calling htmlCtxtUseOptions with HTML_PARSE_NOWARNING causes the warning handlers to be unregistered (set to NULL). But the PHP code then proceeds to install its own handlers unconditionally, rendering the flag useless. 

see stackoverflow

Test script:
$doc=new DOMDocument();
$doc->loadHTML("<tagthatthrowswarning>HI</tagthatthrowswarning>", LIBXML_NOWARNING);
echo $doc->saveHTML();

Expected result:
expected output 
no warnings output.

Actual result:
E_WARNING : type 2 -- DOMDocument::loadHTML(): Tag tagthatthrowswarning invalid in Entity, line: 1 -- at line 4


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-27 19:03 UTC]
-Status: Open +Status: Verified
 [2017-01-27 19:03 UTC]
Confirmed: <>.
 [2017-02-03 06:14 UTC]
Automatic comment on behalf of
Log: Fixed bug #74004 LIBXML_NOWARNING (etc) ignored by DOMDocument::loadHTML
 [2017-02-03 06:14 UTC]
-Status: Verified +Status: Closed
 [2017-02-03 19:06 UTC]
-Status: Closed +Status: Re-Opened
 [2017-03-02 11:38 UTC]
-Status: Re-Opened +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-03-07 21:25 UTC] svnpenn at gmail dot com
Why is this still producing an error?

$ cat html.php
$doc = new DOMDocument();
$doc->loadHTML('<tagthatthrowswarn>HI</tagthatthrowswarn>', LIBXML_NOWARNING);

$ php -v
PHP 7.3.7 (cli) (built: Jul 21 2019 18:10:35) ( NTS )

$ php html.php
PHP Warning:  DOMDocument::loadHTML(): Tag tagthatthrowswarn invalid in Entity,
line: 1 in /Desktop/html.php on line 3
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Jun 07 10:01:24 2020 UTC