annotations
annotations copied to clipboard
AnnotationRegistry fallback to class_exists doesn't seem to work
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.
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)
This should have been fixed in https://github.com/doctrine/annotations/pull/323
Thanks for pointing this out @W0rma! @ChrisTitos can you please check with the latest release and let me know if this is fixed?
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 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.