我在 Windows 7(64 位)系统上使用 Zend Server CE。
我正在使用 Zend Framework 2.0 开发一个网站。在本网站中,我使用 DOMDocument 来分析外部网站(由 URL 给出)。
我使用 Zend Framework 1.12 和 Zend Server CE 4 (PHP 5.2) 开始这个项目。现在我安装了 Zend Server CE 5.6.0(apache2.2、PHP 5.3.14、ZF2-Support)。我用 ZF2.0 重建我的项目。一切正常...除了一个功能。
当我尝试实例化 DOMDocument 时收到此错误消息 (php-error.log):
Fatal error: Class 'Application\Controller\DOMDocument' not found in
_Path_\module\Application\src\Application\Controller\SearchbarController.php on line 81
在 PHP 5.2 (ZF 1.12) 和 Zend Server CE 4 中,此功能可以完美运行。但是现在...没有任何更改,它会抛出此错误。
PHP 5.3 内置了 dom 扩展和 xml 扩展。我检查了 phpinfo 和我的 php.ini,这些扩展正在运行。
我读到,我应该安装 php-xml。但是 dom、xml 和 libxml 正在运行...我为什么要重新安装它们?
不知道,为什么升级Zend Server CE后DOMDocument无法实例化。可能是 ZF2.0 是此错误的可能原因。但我找不到任何指向此的内容。
最佳答案
简而言之,是命名空间的引入(PHP 5.3 的特性被 ZF2 大量使用——但不是 ZF 1.x)导致了这个错误。用这条线...
$dom = new DOMDocument(...)
... ZF 只检查当前导入的命名空间是否属于此类。它会导致失败,因为 DOMDocument
类实际上属于全局命名空间。
解决方法很简单,当你看到原因时:在类名前面使用全局命名空间说明符
- \
符号。像这样:
$dom = new \DOMDocument(...)
关于php - fatal error : DOMDocument not found after Zend Server CE Update,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13323405/