php - fatal error : DOMDocument not found after Zend Server CE Update

标签 php windows-7 zend-framework2 domdocument zend-server-ce

我在 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/

相关文章:

php - 是否可以在 FuelPHP 中路由所有带有破折号的 URL?

windows - 作为低完整性进程运行时如何获取 %temp%\Low 的位置

php - fatal error : Call to a member function getId() on null in doctrine

javascript - 模态布局放在哪里以及如何用动态内容填充它

linux - ZF2 Routing 在 OS X 上工作但在 linux 上失败

php - 如何获取批处理文件使用 PHP 发送电子邮件?

php - mysql 并选择到 OUTFILE - 将二进制数据写入文件

php - 在PHP中将 'while'中的 'foreach'改为 'mysql_fetch_row'

windows - 使用 PowerShell 设置 DNS

windows-7 - 重击 : ssh-host-config: command not found