php / php-src

The PHP Interpreter
https://www.php.net
Other
38.22k stars 7.75k forks source link

Warning: Dom\HTMLDocument::createFromString(): tree error unexpected-token-in-initial-mode in Entity #16807

Closed askonomm closed 2 hours ago

askonomm commented 9 hours ago

Description

The following code:

<?php

$dom = HTMLDocument::createFromString('<p>hello</p>', HTML_NO_DEFAULT_NS);

Resulted in this output:

Warning: Dom\HTMLDocument::createFromString(): tree error unexpected-token-in-initial-mode in Entity

But I expected this output instead:

It to work normally, given that it gets a perfectly valid piece of HTML. It doesn't break the HTML parsing, so it seems to work, but for some reason throws a warning.

PHP Version

PHP 8.4.0 RC1

Operating System

Debian 12

devnexen commented 5 hours ago

hmmm do not know if that is a bug, i.e. if we are supposed to pass a full valid html doc. But I do not have the full picture so cc @nielsdos.

nielsdos commented 2 hours ago

The dtd is missing, so the document is actually not standard compliant. You can silence this by passing LIBXML_NOERROR to the options as well (using bitwise OR).