Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony app_dev.php install \DOMDomain error

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 ?

like image 986
user3334360 Avatar asked Feb 20 '14 20:02

user3334360


2 Answers

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

like image 127
bernland Avatar answered Oct 12 '22 16:10

bernland


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.

like image 27
Pedro Cordeiro Avatar answered Oct 12 '22 16:10

Pedro Cordeiro