Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in classExists when using multiple autoloaders (i.e. ZF2) #184

Closed
wants to merge 3 commits into from

Conversation

bramstroker
Copy link

The autoloading routine in the classExists method makes the assumption the autoload method always returns a value (i.e. no void) when the autoloading of a class is succesfull. When you have multiple autoloaders registered to the spl stack this can lead to problems. In my case I'm using ZF2 ClassmapAutoloader and StandardAutoloader as fallback. The classmapAutoloader returns nothing so the autoload method in the StandardAutoloader is called as well, because the for loop is continued. This results in a second include, and a fatal error "Cannot redeclare class" is triggered.

@schmittjoh
Copy link
Member

Loaders that you pass to the AnnotationRegistry must return a boolean.

However, you can easily wrap the Zend autoloader instead of passing it directly:

AnnotationRegistry::registerLoader(function($name) use ($zendLoader) { 
    $zendLoader->autoload();

    return class_exists($name, false);
});

@schmittjoh schmittjoh closed this Sep 17, 2012
@Fgruntjes
Copy link

The problem has nothing to do with the AnnotationRegistry. Its the fact that Doctrine\Common\ClassLoader::classExists() uses spl_autoload_functions() to see if it can load a class. In my application we have multiple ZF2 autoloaders registered with spl_autoload_register(). This function does not dictate a return value however the Doctrine\Common\ClassLoader::classExists() does not work properly if there are auto load methods / functions registered without a return value.

@schmittjoh
Copy link
Member

Ups, I was too fast here!

Sorry :)

@schmittjoh schmittjoh reopened this Sep 18, 2012
@ghost ghost assigned beberlei Sep 21, 2012
@Ocramius
Copy link
Member

This was handled in #216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants