Repository navigation
Typed property DOMDocument::$documentElement must not be accessed before initialization #12215
Description
Activity
- added 5 commits that reference this issue
on Sep 15, 2023 - added 2 commits that reference this issue
on Sep 20, 2023 OK, I have no run into this error as well on my VM with Ubnutu 22.04.
php -v PHP 8.1.12-1ubuntu4.3 (cli) (built: Aug 17 2023 17:37:48) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.12, Copyright (c) Zend Technologies with Zend OPcache v8.1.12-1ubuntu4.3, Copyright (c), by Zend TechnologiesCode that triggers this error. I am not a php developer, just a user that is stuck with a presumably functioning plugin that fails to function on my brand new VM. This is a short code snippet that is designed to generate the error that crashes the plugin:
<?php try { $xml = new \DOMDocument('1.0', 'UTF-8'); $xml_string = <<<'EOT' <?xml version="1.0" encoding="UTF-8"?> <dummy> </dummy> EOT; if ($xml->loadXML($xml_string)) { var_dump($xml->documentElement); } else { echo "Invalid XML string"; } } catch (Error $e) { echo '<pre>'.$e.'</pre>'; } ?>Error:
Error: Typed property DOMDocument::$documentElement must not be accessed before initialization in /var/www/*****/test2.php:11 Stack trace: #0 {main}DOM section of the php.ini
DOM/XML enabled DOM/XML API Version 20031129 libxml Version 2.9.14 HTML Support enabled XPath Support enabled XPointer Support enabled Schema Support enabled RelaxNG Support enabled I have no option to use a higher version of php because one is not available in the official lunar channel, and I cannot install ondrej/ppa because no repo is available for my version of ubuntu. Attempting to add the ppa fails with a 404.
Help?
@vmajor you are somehow loading the DOM extension twice, causing it to get confused.
Either the DOM extension is embedded in the php binary, and you don't need to load it in the php.ini again. In that case remove the extension line for DOM in php.ini.
Or you are loading it twice in the php.ini and you have to remove the duplicate line.I have no experience with ppa.
But in any case, you can always install a newer PHM version by compiling from the git repo yourself.Reacted by vmajor and VictorOh... thank you for the extremely fast, and correct reply. I had only one instance of DOM in php.ini, but I commented it out and now the test script works. Next, testing the presumably functional plugin.
Thank you so much.
@vmajor you are somehow loading the DOM extension twice, causing it to get confused. Either the DOM extension is embedded in the php binary, and you don't need to load it in the php.ini again. In that case remove the extension line for DOM in php.ini. Or you are loading it twice in the php.ini and you have to remove the duplicate line.
I have no experience with ppa. But in any case, you can always install a newer PHM version by compiling from the git repo yourself.
Also managed to me. Thank's a lot.
Just removed from my php.ini file;extension=dom
Description
The following code:
Resulted in this output:
But I expected this output instead:
Exact reproduction steps on a fresh Ubuntu 22.04 VM:
apt install php8.1 php-xmlsed -i '/Dynamic Extensions/a extension=dom.so' /etc/php/8.1/apache2/php.ini(i.e. addingextension=dom.soto the dynamic extensions section of php.ini).systemctl restart apache2Note: The cause of the issue is a configuration error on the users end, but the error message is very non-descript and thus hard to debug. This issue is intended to ask for an improvement in error reporting (e.g. emitting an error because the extension is laoded twice or because a necessary dependency is not loaded in the right order).
PHP Version
PHP 8.1.2
Operating System
Ubuntu 22.04