Hello Matthew
Thank you very much for your response.
> 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...)
So, I guess that the best thing for me to do in this case is to
restructure my class library ("Foo"), getting rid of the actual class
"Foo".
Indeed, the class "Foo" only contains some class constants, which
define certain globally used information (like database usernames
etc).
> 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).
Thank you for clarifying this too. I was not aware of this situation exactly.
Jonathan Maron
On Mon, May 4, 2009 at 2:16 PM, Matthew Weier O'Phinney
<[email protected]> wrote:
> -- 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/
>