Problem/Motivation
\Doctrine\Common\Annotations\SimpleAnnotationReader and its supporting classes and tests were from Doctrine in #2631202: Doctrine no longer supports SimpleAnnotationReader, incorporate a solution into core
The main reason we didn't remove the use of SimpleAnnotationReader and use \Doctrine\Common\Annotations\AnnotationReader is because the issue was being resolved near the end of the Drupal 8 cycle and it was deemed too disruptive.
Proposed resolution
Add a deprecation message for any classes that are using annotation without the annotation use statements.
Remove forked SimpleAnnotationReader and use \Doctrine\Common\Annotations\AnnotationReader in Drupal 10
Remaining tasks
All
User interface changes
API changes
Annotations will have to add use statements for any classes used in the annotations. Just like every other project using Doctrine Annotaitons
Comments
Comment #3
xjmThe deprecation is a side effect of adopting the new API, so tagging accordingly.
This isn't a 9.0.x-only change (i.e., we should do this in a minor with BC/deprecations/continuous upgrade path), so moving to 9.1.x.
Comment #6
donquixote commentedI want to mention another alternative to Doctrine annotation reader.
https://github.com/spiral/attributes
This brings backwards support for PHP 8 attributes, but also supports annotations.
I have not really studied
\Doctrine\Common\Annotations\AnnotationReaderas an alternative, so can't really advocate for one or the other atm. But I think we do want to move towards towards attributes at some point.Comment #7
andypostOTOH probably symfony provides newer version as they adopted native attributes
Comment #8
andypostAnd here some discussion #3223435: Track PHP 8.1 support in hosting and distributions
Comment #9
donquixote commentedBtw, one question related to this:
Do we still want to prevent class files from being included during discovery?
That is, do we still need StaticReflectionParser + StaticReflectionClass? Or could we use native reflection instead?
I don't remember why we decided to use StaticReflectionParser in the past, I can think of the following reasons:
For the first issue, I found the following:
Comment #10
longwave@donquixote I think the memory and performance concerns are still valid. The Doctrine StaticReflectionParser (that we now adopted into core in #3180351: doctrine/reflection is abandoned) has an optional optimisation when we only want to read class docblocks, this avoids parsing most of the PHP.
Once we are on a minimum of PHP 8 we can start migrating to native attributes, but we still might want a faster/cheaper way of parsing these than loading all the code.
Comment #11
andypostI bet in a light of JIT
-dopcache.jit_buffer_size=20Mit will be faster to loadMoreover core could benefit from preload and so on
- #3108687: Compatibility with/take advantage of code preloading in PHP 7.4
- #2218651: [meta] Make Drupal compatible with persistent app servers like ReactPHP, PHP-PM, PHPFastCGI, FrankenPHP, Swoole
Comment #12
donquixote commentedSeems I am wrong here.
The variables from the parser can be wiped after each file, assuming we don't cache them in memory. The memory for PHP opcode stay during the entire process/request.
(However, with preload or whatever, as mentioned by @andypost, if we assume that the opcode is already in memory all the time, that would be ok)
As for performance:
(As a benefit, we can add forward support for advanced attributes syntax (e.g. objects in arg values).)
(However, we will be stuck with whatever is supported in that version of PHP, because PHP will always parse it when loading the file, and fatal out: https://3v4l.org/T5n3n.)
Comment #13
andypostThere's related issue which also raised few concerns #2919424: Deprecate annotations, one of the four plugin discovery approaches
Comment #14
donquixote commentedBut I don't want to deprecate annotations :)
Unless moving to attributes qualifies as that.
Comment #16
andypostComment #17
andypostAs core 10 requires PHP 8.1 it looks more promissing
Comment #18
andypostit's fixed in PHP 8.1 - so no longer a blocker
PS: Symfony also faced it but it's hard to change it in 6.0
Comment #19
andypostProbably #3252386-104: Use PHP attributes instead of doctrine annotations and next comments will cause a split or meta
Comment #20
alexpottGiven the requiring PHP 8.1 for Drupal 10 means that using attributes instead of annotations is possible I think we should close this issue as we won't do this.