ZF-6645: zend tool's "zf create action" command throws error

Description

{{C:\www\vhosts\localhost\myzendapp>zf create action test index}} {{PHP Fatal error: Cannot redeclare class Zend_OpenId_Provider in C:\www\vhosts\localhost\myzendapp\library\Zend\OpenId\Provider.php on line 44}} {{Fatal error: Cannot redeclare class Zend_OpenId_Provider in C:\www\vhosts\localhost\myzendapp\library\Zend\OpenId\Provider.php on line 44}}

STATUS: Clean new untouched project created with the same tool by executing: {color:red} {{zf create project myzendapp}}{color}. Zend libraries added to library dir as instructed. Application runs with no problems. SERVER: Apache 2.2 with all necessary mods activated (tested for .htaccess), PHP 5.2.5 SYSTEM: WinXP SP3

Comments

The issue is more likely to be related with zend_tool than with zend_openid (it seems to me..). Assigning to other component.

Assigning to Ralph, as related primarily to Zend_Tool.

I try to reproduce on 1.8.4, WinXP, PHP 5.2.8


zf.bat create project C:\temp\zftest\0624
cd C:\temp\zftest\0624
zf.bat create action test index

I find no errors now. It seems to be already solved.

I'm seeing this same error under Solaris 10 with php 5.3.0 and Zend 1.8.4. Any ideas?

sh zf.sh create project myzendapp PHP Fatal error: Cannot redeclare class Zend_OpenId_Provider in /usr/opt/php/lib/php/Zend/OpenId/Provider.php on line 44

Fatal error: Cannot redeclare class Zend_OpenId_Provider in /usr/opt/php/lib/php/Zend/OpenId/Provider.php on line 44 /usr/opt/bin/php -d safe_mode=Off -f ./zf.php -- create project myzendapp

/usr/opt/bin/php -v PHP 5.3.0 (cli) (built: Jul 8 2009 11:56:08) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies

It looks like this may be an include path error.

When I set the environmental variable

export ZEND_TOOL_INCLUDE_PATH="/path/to/ZendFramework/library";

the problem disappears for me.

I was able to reproduce this error by having two copies of the Zend Framework installed. I'm still not sure exactly why both are being loaded, but I'll describe my setup and more evidence of the bug here.

include_path => .:/usr/share/php:/usr/share/pear => .:/usr/share/php:/usr/share/pear

I have one freshly downloaded copy of the Zend Framework at: /usr/share/php/ZendFramework-1.8.4/library/Zend/

and the current (somewhat old) ubuntu Zend Framework package at: /usr/share/php/libzend-framework-php/Zend/

plus a soft link to the latest package like this: /usr/share/php/Zend -> /usr/share/php5/ZendFramework-1.8.4/library/Zend/

Here's the buggy script output: $ /usr/share/php5/ZendFramework-1.8.4/bin/zf.sh

Fatal error: Cannot redeclare class Zend_OpenId_Provider in /usr/share/php5/ZendFramework-1.8.4/library/Zend/OpenId/Provider.php on line 44

Call Stack: 0.0004 74076 1. {main}() /usr/share/php5/ZendFramework-1.8.4/bin/zf.php:0 0.0108 623348 2. Zend_Tool_Framework_Client_Console::main() /usr/share/php5/ZendFramework-1.8.4/bin/zf.php:77 0.0108 623784 3. Zend_Tool_Framework_Client_Abstract->dispatch() /usr/share/php5/ZendFramework-1.8.4/library/Zend/Tool/Framework/Client/Console.php:86 0.0108 623904 4. Zend_Tool_Framework_Client_Abstract->initialize() /usr/share/php5/ZendFramework-1.8.4/library/Zend/Tool/Framework/Client/Abstract.php:192 0.0137 750808 5. Zend_Tool_Framework_Loader_Abstract->load() /usr/share/php5/ZendFramework-1.8.4/library/Zend/Tool/Framework/Client/Abstract.php:101 1.1997 2751124 6. include_once('/usr/share/php5/ZendFramework-1.8.4/library/Zend/OpenId/Provider.php') /usr/share/php5/ZendFramework-1.8.4/library/Zend/Tool/Framework/Loader/Abstract.php:90

I gained a little insight into this by checking the contents of $this->retrievedFiles in Zend_Tool_Framework_Loader_Abstract right before the loop where the exception is thrown. Here's what I saw: Array ( [0] => /usr/share/php5/libzend-framework-php/Zend/OpenId/Provider.php [1] => /usr/share/php5/ZendFramework-1.8.4/tests/Zend/Tool/Framework/Manifest/_files/ManifestBadProvider.php [2] => /usr/share/php5/ZendFramework-1.8.4/library/Zend/Tool/Project/Provider/Manifest.php [3] => /usr/share/php5/ZendFramework-1.8.4/library/Zend/Tool/Project/Provider/ProjectProvider.php [4] => /usr/share/php5/ZendFramework-1.8.4/library/Zend/Tool/Framework/Client/Console/Manifest.php [5] => /usr/share/php5/ZendFramework-1.8.4/library/Zend/Tool/Framework/System/Manifest.php [6] => /usr/share/php5/ZendFramework-1.8.4/library/Zend/Tool/Framework/System/Provider/Manifest.php [7] => /usr/share/php5/ZendFramework-1.8.4/library/Zend/OpenId/Provider.php )

Obviously, it will throw this error when it tries to load the second copy of Zend_OpenId_Provider, but I'm still not sure why it references the wrong one in the first entry there.

Is there a reason we can't just do something like this? (patch attached)

Hi, Stephan, It may be solved by using only one library.in include_path.

I think you may use 2 libraries in your include_path now, so it would cause confusing..

Hi Satoru,

I do have two libraries in my include path, but if you examine the source code for Zend_Tool_Framework_Loader_IncludePathLoader, you'll find this section which obviously doesn't work:

// ensure that we only traverse a single version of Zend Framework on all include paths if (file_exists($realIncludePath . '/Zend/Tool/Framework/Loader/IncludePathLoader.php')) { if ($isZendTraversed === false) { $isZendTraversed = true; } else { // use the deny directory pattern that includes the path to 'Zend', it will not be accepted $filterDenyDirectoryPattern = '.*((/|\\).svn|' . preg_quote($realIncludePath . DIRECTORY_SEPARATOR) . 'Zend)'; } }

Because this component tries and fails to cover the case of multiple libraries, I still consider this a bug.

I finally got back to working on a resolution for this on our solaris server. Here is the resolution that worked for me. I did install the latest release but that did make any difference.

  1. Make sure you use the gnu version of tar to do the extract of the gz file.

  2. I updated the zf.sh script so that I had a fixed command line to get around standard solaris not installing readlink. I used the following command for execution:

    /usr/opt/bin/php -d safe_mode=Off -f /path/to/ZendFramework-1.9.1-minimal/bin/zf.php -- $@

3.. set environment variable ZEND_TOOL_INCLUDE_PATH=/path/to/ZendFramework-1.9.1-minimal/library

  1. Make sure you don't have the Zend framework in your include_path twice as described above.

Step number 4 produces this error:

Fatal error: Cannot redeclare class Zend_OpenId_Provider in /usr/opt/php/lib/php/Zend/OpenId/Provider.php on line 44

Step number 1 resolved a problem for me where the command lines passed to zf.sh produced no output but simply returned.

Note that in my previous comment I meant to say that the new installation did NOT make any difference.

Fixed in r18416 as part of ZF-7940, will be in 1.10