annotations icon indicating copy to clipboard operation
annotations copied to clipboard

AnnotationRegistry fallback to class_exists doesn't seem to work

Open ChrisTitos opened this issue 4 years ago • 5 comments

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.

ChrisTitos avatar Apr 07 '20 15:04 ChrisTitos

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)

stof avatar Apr 07 '20 18:04 stof

This should have been fixed in https://github.com/doctrine/annotations/pull/323

W0rma avatar Apr 21 '20 07:04 W0rma

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

alcaeus avatar Apr 21 '20 08:04 alcaeus

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.

ChrisTitos avatar Apr 21 '20 09:04 ChrisTitos

@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.

stof avatar Jul 30 '20 07:07 stof