Home » Php » javascript – Symfony app_dev.php install \DOMDomain error

javascript – Symfony app_dev.php install \DOMDomain error

Posted by: admin July 12, 2020 Leave a comment


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
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();


$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 ?

How to&Answers:

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


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.