Autoload with namespaces in PHP 5.3?

2019-04-18 23:47发布

问题:

How do you use _autoload in PHP 5.3 with namespaces? I have a main autoload function in a namespace separate from my script. I'm also calling a class with a different namespace. (It's not surprising, but) It's not finding the autoload function. Do I have to recreate the autoload function for each namespace? That seems suboptimal.

Thanks in advance for any help!

回答1:

From a comment in the PHP manual:

To use autoload function with namespaces you should remember to define it in main scope in "\" namespace.