最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Symfony app_dev.php install DOMDomain error - Stack Overflow

programmeradmin3浏览0评论

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 ?

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 ?

Share Improve this question edited Feb 20, 2014 at 20:08 TN888 7,7399 gold badges52 silver badges85 bronze badges asked Feb 20, 2014 at 20:05 user3334360user3334360 711 silver badge3 bronze badges 1
  • on FreeBSD, the extension is called php70-dom (for php7) – Razvan Tudorica Commented Jul 31, 2016 at 20:29
Add a ment  | 

2 Answers 2

Reset to default 11

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.

发布评论

评论列表(0)

  1. 暂无评论