Search code examples
phpzend-frameworknamespaceszend-autoloader

Will a directory with a period break autoload resolution based on a namespace in Zend Framework?


I have a folder in my library folder which is named after my website. The folder path is like:

~\www\library\myWebsite.com

If I'm using Zend autoloader to load the namespace of everything in the library path, will I have any trouble autoloading a class from that file with a namespace like this:

\myWebsite.com\myClass::myFunction();

I have looked online for documentation on this and I can't find any info about using periods in this way.


Solution

  • I tried it and the complication is in PHP. I think Zend is registering the namespace fine, because when I call \Zend_Load_Autoloader::getRegisteredNamespaces() it shows that it's registered. but when I call the static method from the fully qualified namespace, php gives an error of this:

    Fatal error: Undefined constant 'myWebsite' in /home/jesse/www/application/controllers/MyController.php on line 15 
    

    It seems like PHP is terminating the namespace identifier, during parsing, at the . (period character). This is dissapointing because to me having a library named after the website was important to my design.

    I will rename the directory to myWebsitecom or possibly make the .com it's own sub directory like

    myWebsite\com and incorporate that into my namespace tree like: \MyNamespace\Com\MyClass::myFunction();