-- Jonathan Maron <[email protected]> wrote
(on Monday, 04 May 2009, 07:53 AM +0200):
> I use the Zend_Loader_Autoloader to load classes. My namespace is "Foo".
>
> According to the docs (http://is.gd/v5zW) I should provide an
> underscore after the namespace:
>
> require_once 'Zend/Loader/Autoloader.php';
>
> $autoloader = Zend_Loader_Autoloader::getInstance();
> $autoloader->registerNamespace('Foo_');
>
> When I try to access a class constant (echo Foo::CONST), however, I
> get the following error:
>
> Fatal error: Class 'Foo' not found in /var/www/[..]/www/index.php on line 38
That's because class 'Foo' does not have a namespace prefix. (Hint: this
is one reason why we no longer have a Zend.php with class Zend...)
> Changing autoloader's registerNamespace to "Foo" (without the
> underscore) rectifies the problem:
>
> $autoloader->registerNamespace('Foo');
>
> Similarly, using $autoloader->setFallbackAutoloader(true) works as expected.
>
> Is this intended behavior, a bug (in code and/or documentation) or am
> I missing something?
We recommend using the fully qualified namespace, which includes an
underscore, to ensure that you match *exactly* the namespace. As an
example, we have two namespaces, Zend_ and ZendX, by default; if we
hadn't used underscores, we would have had a collision between the two
(Zend would match ZendX).
--
Matthew Weier O'Phinney
Project Lead | [email protected]
Zend Framework | http://framework.zend.com/