2010年1月19日星期二

Re: [fw-mvc] Little trouble with Zend Framework 1.10.0

-- Marcel Alburg <m.alburg@weeaar.com> wrote
(on Sunday, 17 January 2010, 10:43 PM +0100):
> i try the new and the old version from 1.10 and have the same error in the class Zend_Exception.
>
> If i include/require the the class Zend/Exception.php i get the error:
>
> php test.php
>
> Fatal error: Cannot redeclare class Zend_Exception in /tmp/Exception.php on line 28
>
> Call Stack:
> 0.0020 90968 1. {main}() /tmp/test.php:0
> 0.0033 125432 2. require_once('/tmp/Exception.php') /tmp/test.php:2
>
>
> The File:
>
> <?php
> require_once 'Exception.php';

Actually, on looking at this again... it looks like you're doing
something non-standard.

Please make sure the entire Zend Framework library is installed, that
it's under a single tree containing the directory "Zend", and that the
parent directory of the "Zend" directory is on your include_path. Then,
when loading a file, always make sure that you load starting with the
"Zend/" directory.

As an example, when you unpack the ZF archive, you'll get a directory
structure like the following:

bin/
demos/
documentation/
library/
Zend/
...
tests/

You'd add the directory "library" to your include_path:

set_include_path('.:/path/to/zf/library');

And then:

require_once 'Zend/Exception.php';

My suspicion is one of several things:

(a) you've got the ZF library on your include_path already, and
you're using autoloading. In this case, when you do
"require_once 'Exception.php';" you're loading an already loaded
class file via a different path, which leads to the conflict.

(b) you've got another version of ZF already on the path that has
already been in use, and now you're explicitly loading a single file
that redefines a class already loaded.

(c) you have an opcode cache in play that's potentially stripping
out the conditionals.

(d) you're using an opcode cache, Zend_Exception is already in
memory, and now you're doing an explicit require_once to a file not
on your include_path that redefines it.

If your file is really as simple as what you display above, check your
php.ini, and see if you've got an auto_prepend_file declaration; this
could account for ZF already being loaded. As for (c) and (d), you'll
have to experiment with those on your own, and investigate what, if any,
opcode cache you're using, and how to disable it or flush its cache.

I've tested loading 'Zend/Exception.php' locally via a number of
mechanisms, and am not getting the issue you describe. The else
condition will never be executed if your version is < 5.3.0, and if your
version is < 5.3.0, the only way Zend_Exception would already be defined
is if a classfile containing it had previously been loaded.

> My PHP Version is: 5.2.6-1+lenny4
>
> If i remove the else section in the Exception.php it works correctly
> and the first section is load because my php version is lower than
> 5.3.0.

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

没有评论: