问题
I recently re-opened an old (1 year) Symfony project and I am having an error on every page (I don't remember having this issue a year ago) :
[exception] 500 | Internal Server Error | Symfony\Component\Config\Exception\FileLoaderLoadException
/var/www/[...]/wdt.xml
ContextErrorException: Notice: Undefined property: DOMDocument::$documentElement
If I clear the cache, the error disappear but as soon as I edit and save a file, the error is showing up again. The project was using Symfony 2.8 and I updated to Symfony 3.2 but it didn't solve the issue.
I don't think the problem is related to the wdt.xml file and I think it might be related to my laptop config.
I don't really know where to start to investigate so any suggestion is welcome!
Edit 1 :
I am actually having the same problem with another project I created few days ago. The project don't use any additional bundles and I just created 5 entities and generated the MySQL database.
Edit 2 :
After some more researched, I decided to create a new Ubuntu VM and test a new Symfony project and it just work perfectly so it must be something to do with the configuration on my laptop.
Edit 3 :
After some more tests, here is what I get when I add a print_r($dom); in the file XmlUtils.php (vendor/symfony/symfony/src/Symfony/Component/Config/Util/XmlUtils.php) line 59 :
Ubuntu VM (no error) :
DOMDocument Object ( [doctype] => [implementation] => (object value omitted) [documentElement] => (object value omitted) [actualEncoding] => [encoding] => [xmlEncoding] => [standalone] => 1 [xmlStandalone] => 1 [version] => 1.0 [xmlVersion] => 1.0 [strictErrorChecking] => 1 [documentURI] => /var/www/my_project/web/ [config] => [formatOutput] => [validateOnParse] => 1 [resolveExternals] => [preserveWhiteSpace] => 1 [recover] => [substituteEntities] => [nodeName] => #document [nodeValue] => [nodeType] => 9 [parentNode] => [childNodes] => (object value omitted) [firstChild] => (object value omitted) [lastChild] => (object value omitted) [previousSibling] => [attributes] => [ownerDocument] => [namespaceURI] => [prefix] => [localName] => [baseURI] => /var/www/my_project/web/ [textContent] => %kernel.charset% %kernel.default_locale% )
Ubuntu laptop (error) :
DOMDocument Object ( [validateOnParse] => 1 [nodeName] => #document [nodeValue] => [nodeType] => 9 [parentNode] => [childNodes] => (object value omitted) [firstChild] => (object value omitted) [lastChild] => (object value omitted) [previousSibling] => [attributes] => [ownerDocument] => [namespaceURI] => [prefix] => [localName] => [baseURI] => /var/www/lab/symfony/booklib/web/ [textContent] => %kernel.charset% %kernel.default_locale% )
It looks like there is some missing information on my laptop...
So basically, the function $dom->loadXML doesn't return the same value on my laptop environment and inside the VM... any idea why?
回答1:
I have Ubuntu 16.04 installation with php7.0.15, and i fixed the error by just removing php-xdebug extension.
sudo apt-get purge php-xdebug
回答2:
I finally resolved the problem by uninstalling / reinstalling php7. I have no idea why I had this issue though...
回答3:
In my case the error was triggered by the dom.so extension being loaded in two places. Removing one fixed the problem.
回答4:
This is very strange BUT try to change php extensions load order in php config. This solve my problem... move dom extension above or below in list
回答5:
Hi I also meet this problem. The way I resolve it is:
composer update
Hope that help some one.
回答6:
Thank @pjehan. I had the same problem and I've lost a day. Finally, I did like you and it was successful. Just specify one thing: unistall PHP 7.0.x and PHP 7.1.3 intaller (stable version for PHP 7). The link of the version PHP 7 stable: http://php.net/downloads.php Thank you so much, @pjehan, you saved my life :D
回答7:
I solved the problem by disabling xdebug for the cli
回答8:
In my case the dom extension was enabled twice. Once in the dom.ini
and also in the php.ini
. I removed the extension=dom.so
entry from the php.ini and reloaded the apache2 webserver.
来源:https://stackoverflow.com/questions/42785051/notice-undefined-property-domdocumentdocumentelement