Masterminds / html5-php

An HTML5 parser and serializer for PHP.
http://masterminds.github.io/html5-php/
Other
1.55k stars 114 forks source link

Typed property DOMDocument::$documentElement must not be accessed before initialization #220

Open alecpl opened 1 year ago

alecpl commented 1 year ago

I'm unable to reproduce, but one of Roundcube users created a ticket for this here.

This is with PHP 8.1.13:

PHP Fatal error:  Uncaught Error: Typed property DOMDocument::$documentElement must not be accessed before initialization in /var/www/roundcube/vendor/masterminds/html5/src/HTML5/Parser/DOMTreeBuilder.php:275
Stack trace:
#0 /var/www/roundcube/vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php(399): Masterminds\HTML5\Parser\DOMTreeBuilder->startTag()
#1 /var/www/roundcube/vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php(141): Masterminds\HTML5\Parser\Tokenizer->tagName()
#2 /var/www/roundcube/vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php(82): Masterminds\HTML5\Parser\Tokenizer->consumeData()
#3 /var/www/roundcube/vendor/masterminds/html5/src/HTML5.php(161): Masterminds\HTML5\Parser\Tokenizer->parse()
#4 /var/www/roundcube/vendor/masterminds/html5/src/HTML5.php(89): Masterminds\HTML5->parse()
#5 /var/www/roundcube/program/lib/Roundcube/rcube_washtml.php(698): Masterminds\HTML5->loadHTML()
stof commented 1 year ago

Should be closed as the roundcube ticket was closed saying that upgrading PHP and roundcube fixed the issue.

mti-1 commented 1 year ago

Got the same problem on PHP8.1.18, but I can't update to PHP8.2 right now. Do you know what could cause the problem ?

stof commented 1 year ago

try to update to PHP 8.1.19 (the latest 8.1 version). It might be enough to fix the issue.

mti-1 commented 1 year ago

Solved it, I had an extension=dom inside a php.ini file, maybe there was a conflict because of this. i've been stuck 3 days on this.

nielsdos commented 11 months ago

Fwiw this was a php bug and is fixed in 8.1.25 and 8.2.12 (not released yet)

stof commented 11 months ago

@nielsdos can you link to the PHP bug (or to the PR fixing it) ?

nielsdos commented 11 months ago

@stof fix for stable versions: https://github.com/php/php-src/pull/12219 fix for master: https://github.com/php/php-src/pull/12246