From: missingno at ifrance dot com Operating system: Ubuntu 7.10 PHP version: 5.3CVS-2008-01-06 (snap) PHP Bug Type: DOM XML related Bug description: validateOnParse & validate() give difference results
Description: ------------ >From what I understand, DOMDocument::validateOnParse() = TRUE & DOMDocument::validate() should return the same list of errors for a given document. But when dealing with HTML code, validate() seems to fail to deal with the DTD correctly. Therefore, using validate() & validateOnParse gives different results. I think that in the case of validate(), PHP calls libxml with options that make it think it will be dealing with XML code and thus, an XML DTD. So, once libxml loads the HTML DTD, it fails to parse it correctly and returns a bunch of errors. (HTML & XML DTDs are similar, except that HTML ones allow for some more constructs like the '&' operator in ELEMENT declarations) Reproduce code: --------------- <?php /* Note: removing the system identifier doesn't change the result, * except that "errors" in the DTD are caught immediately. * (My guess would be that libxml tries to fetch the DTD from the * system identifier instead of using a catalog for resolution) */ $markup = <<<HTML <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head><title>Foo</title></head> <body><p>Bar</p></body> </html> HTML; header('Content-Type: text/plain'); libxml_use_internal_errors(TRUE); // First, using DOMDocument::validateOnParse. libxml_clear_errors(); $dd1 = new DOMDocument(); $dd1->validateOnParse = TRUE; echo "Using validateOnParse:\n"; $dd1->loadHTML($markup); var_dump(libxml_get_errors()); echo "\n\n"; // Now, using DOMDocument::validate() instead. libxml_clear_errors(); $dd2 = new DOMDocument(); $dd2->validateOnParse = FALSE; echo "Using validate():\n"; $dd2->loadHTML($markup); $dd2->validate(); var_dump(libxml_get_errors()); ?> Expected result: ---------------- Using validateOnParse: array(0) { } Using validate(): array(0) { } Actual result: -------------- Using validateOnParse: array(0) { } Using validate(): array(3) { [0]=> object(LibXMLError)#3 (6) { ["level"]=> int(3) ["code"]=> int(37) ["column"]=> int(1) ["message"]=> string(55) "xmlParseEntityDecl: entity HTML.Version not terminated " ["file"]=> string(36) "http://www.w3.org/TR/html4/loose.dtd" ["line"]=> int(31) } [1]=> object(LibXMLError)#4 (6) { ["level"]=> int(3) ["code"]=> int(60) ["column"]=> int(1) ["message"]=> string(37) "Content error in the external subset " ["file"]=> string(36) "http://www.w3.org/TR/html4/loose.dtd" ["line"]=> int(31) } [2]=> object(LibXMLError)#5 (6) { ["level"]=> int(2) ["code"]=> int(517) ["column"]=> int(0) ["message"]=> string(74) "Could not load the external subset "http://www.w3.org/TR/html4/loose.dtd" " ["file"]=> string(0) "" ["line"]=> int(0) } } -- Edit bug report at http://bugs.php.net/?id=43771&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43771&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43771&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43771&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43771&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43771&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43771&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43771&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43771&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43771&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43771&r=support Expected behavior: http://bugs.php.net/fix.php?id=43771&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43771&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43771&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43771&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43771&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43771&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43771&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43771&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43771&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43771&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43771&r=mysqlcfg