Question

I'm working with Zend Server CE on a Windows 7 (64bit) System.

I'm developing a website with Zend Framework 2.0. In this website I use DOMDocument to analyse an external website (given by URL).

I started this project with Zend Framework 1.12 and Zend Server CE 4 (PHP 5.2). Now I installed the Zend Server CE 5.6.0 (apache2.2, PHP 5.3.14, ZF2-Support). I rebuild my project with ZF2.0. Everything works fine...except one function.

I get this Error-Message (php-error.log), when I try to instantiate DOMDocument:

Fatal error: Class 'Application\Controller\DOMDocument' not found in
_Path_\module\Application\src\Application\Controller\SearchbarController.php on line 81

With PHP 5.2 (ZF 1.12) and Zend Server CE 4, this function worked perfectly. But now...without any change, it throws this error.

The dom-extension and the xml-extension are built-in in PHP 5.3. I checked phpinfo and my php.ini, that these extensions are running.

I read, that i should install php-xml. But dom, xml and libxml are running...why should i re-install them?

I don't know, why DOMDocument could not be instantiated after upgrading the Zend Server CE. May be, that the ZF2.0 is a possible reason for this error. But I can't find anything pointing to this.

Was it helpful?

Solution

In short, it's introduction of namespaces (feature of PHP 5.3 quite heavily used by ZF2 - but not ZF 1.x) that caused this bug. With this line...

$dom = new DOMDocument(...)

... only the currently imported namespace is checked for this class by ZF. And it results in failure, because DOMDocument class actually belongs to the global namespace.

The solution is simple, when you see the reason: use the global namespace specifier - \ symbol - in front of the class name. Like this:

$dom = new \DOMDocument(...)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top