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

AnnotationRegistry fallback to class_exists doesn't seem to work #321

Open
ChrisTitos opened this issue Apr 7, 2020 · 5 comments
Open

Comments

@ChrisTitos
Copy link

I noticed in our codebase after updating to 1.10.1 and removing the deprecated registerLoader('class_exists') call that our custom annotations were not recognized anymore. Getting a "The annotation [...] was never imported. Did you maybe forget to add a "use" statement for this annotation?" error message, though there is in fact a use statement.

I thought pull request #271 would fix that, but it appears that class_exists is not called.

I think I narrowed down the cause to the registerFileUsed flag. In the AnnotationReader constructor is a call to registerFile, which means registerFileUsed is always true, which results in the class_exists fallback never being called.

@stof
Copy link
Member

stof commented Apr 7, 2020

The AnnotationReader should be changed to trigger the loading of the IgnoreAnnotation class instead of using registerFile, so that it does not force using the deprecated way (forcing to load the class is meant to avoid issues for projects using the deprecated way themselves and not having class_exists as a loader, by ensuring that the class is already loaded when the AnnotationRegistry is asked to check for it)

@W0rma
Copy link

W0rma commented Apr 21, 2020

This should have been fixed in #323

@alcaeus
Copy link
Member

alcaeus commented Apr 21, 2020

Thanks for pointing this out @W0rma! @ChrisTitos can you please check with the latest release and let me know if this is fixed?

@ChrisTitos
Copy link
Author

Thanks, I can confirm that the registerFileUsed flag is now false as it should be.

Though now I'm running into another issue where one of the libraries we use still calls registerAutoloadNamespace to load their library specific annotations, which means the fallback still isn't actually called (since $autoloadNamespaces is not empty).
So we still need to manually add the class_exists loader ourselves.

@stof
Copy link
Member

stof commented Jul 30, 2020

@ChrisTitos this is actually expected. The automatic fallback is for projects which don't rely on the old behavior at all. It is intentionally restricted to reduce the BC impact.

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

No branches or pull requests

4 participants