7

I have installed Symfony on localhost under CentOS under VMware player. (Windows 7, 32 bit) My PHP version is 5.3.3. CentOS is 6.5. VMware player is 6.0.1.

When I attempt to connect with localhost/Symfony/web/app_dev.php I get the following error

ClassNotFoundException: Attempted to load class "DOMDocument" from the global namespace in /var/www/html/Symfony/vendor/symfony/symfony/src/Symfony/Component/Config/Util/XmlUtils.php line 47.

Did you forget a use statement for this class?

line 47 is

$dom = new \DOMDocument();

I get 102 hits when I grep "DOMDocument".

Most hits display

$dom = new \DOMDocument();

or

$dom = new DOMDocument(); 

I had previously installed Symfony on an external server following the same script and was able to exercise app_dev.php without problem. (FreeBSD)

What is the difference between new \DOMDocument(); and new DOMDocument();. I am a JavaScript and PHP novice. Does anyone know what I should do to correct this ? or some clues as to how to trouble-shoot ?

1
  • on FreeBSD, the extension is called php70-dom (for php7) Commented Jul 31, 2016 at 20:29

2 Answers 2

11

Running yum install php-xml on CentOS 6.5 solved the problem for me.

Sign up to request clarification or add additional context in comments.

2 Comments

This is the correct answer and show be marked as such.
Solved my problem with a clear instalation on linux mint (using apt-get instead of yum)
3

The backslash (new \DomDocument()) is required when you are loading a class from the global namespace from inside another namespace. In other words, if you used namespace <something> in the top of your file, you will have to use new \DomDocument() to load DomDocument from the global namespace. If you are in the global namespace (the default, if you haven't explicitly declared a namespace), you can use new DomDocument() directly.

If you're getting the error both with the backslash and without it, it's because you're missing a PHP extension: php-xml. Just add extension=dom.so to your php.ini. The extension is bundled with PHP by default.

Run web/config.php to check what's missing.

4 Comments

Hello Pedro. Thanks for the quick answer. I will make thay change and try again. Thank you.
Hello Pedro. I made the change to /etc/php.ini I placed the line "extension=dom.so" right at the top of the .ini file, saved, and re-booted CentOS. I still get the same error. Any other suggestions ? Regards, Lorne
I also ran the config.php. One suggestion is to upgrade to php 5.3.4 or greater. Could this be my problem ? Regards, Lorne.
Hi Pedro ! OK, here is what finally worked. "yum install php-xml". this added the required module and created "/etc/php.d/dom.ini" which contained "extension=dom.so".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.