Autoloading with namespaces in 5.3.0
| From: | Eddie Drapkin | Date: | Sat, 30 May 2009 19:51:56 +0000 |
| Subject: | Autoloading with namespaces in 5.3.0 | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-293390@lists.php.net to get a copy of this message | ||
Hey, I'm looking to start playing with 5.3.0, and thus by extension,
namespaces. One of the things that I definitely need support for is
autoloading, and the docs aren't exactly explicit in some (obvious to me)
cases.
I have an autoloading class that internally handles file-not-found errors
and the like and a set of methods that get registered via
spl_autoload_register. I'm wondering if there's any way that the autoloader
- which won't exist inside a namespace - can handle classes with the same
name in several different namespaces. Say, for example, I have three
directories foo/, bar/, and baz/ and each of those corresponds to a
same-named namespace, and each also has a class named ExampleClass. If I
try to instantate a foo\ExampleClass, does the classname get set in the
autoloader method as "ExampleClass" or "foo\ExampleClass"? If the former,
is there any way to determine the namespace name so I don't accidentally
autoload bar\ExampleClass or baz\ExampleClass?