Re: Autoloading with namespaces in 5.3.0
| From: | Nathan Nobbe | Date: | Mon, 01 Jun 2009 14:44:28 +0000 |
| Subject: | Re: Autoloading with namespaces in 5.3.0 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-293423@lists.php.net to get a copy of this message | ||
On Sat, May 30, 2009 at 1:51 PM, Eddie Drapkin <oorza2k5@gmail.com> wrote:
> 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?
>
i seem to remember a while back, someone saying the entire namespace will
now be passed into the __autoload() function, whereas before it was just the
classname. your autoload logic should be equipped to handle different
classes w/ the same name, in different namespaces.
-nathan