annotations icon indicating copy to clipboard operation
annotations copied to clipboard

Property annotation with several types (union) does not work

Open liayn opened this issue 4 years ago • 4 comments

The lib is used within TYPO3 for annotation evaluation. We stumbled over a case that caused the lib to not parse the annotation at all:

class ThingModel
{
...
    /** @var ThingModel|null|bool */
    protected $related;
...
}

The response of the annotation reader is that there are zero annotations present for $related.

I played around with several variations and it turned out that have two of the three types above as annotation works flawlessly, but having all three (or any other three) types causes the reader to hick-up upon this annotation.

Maybe the parser can be improved to handle such a case?

liayn avatar Oct 08 '21 16:10 liayn

doctrine/annotations is not a phpdoc parser at all. It explicitly ignores the phpdoc annotations for compatibility between doctrine annotations and phpdoc.

stof avatar Oct 08 '21 16:10 stof

Maybe I got something wrong, but TYPO3 definitely extracts @var stuff with the AnnotationReader https://github.com/TYPO3/typo3/blob/master/typo3/sysext/extbase/Classes/Reflection/ClassSchema.php#L220

liayn avatar Oct 08 '21 16:10 liayn

In the default setting @var gets ignores as it is listed here: https://github.com/doctrine/annotations/blob/1.13.x/lib/Doctrine/Common/Annotations/ImplicitlyIgnoredAnnotationNames.php#L82. If however using @var with union types somehow makes our parser it'd be great to have it reproduced as a failing test case.

malarzm avatar Oct 23 '21 12:10 malarzm

Thanks for your information. I'm unfortunately not deep enough into these details. Afaik the TYPO3 implementation uses @var for data type detection of model's properties. So somehow things are parsed, even though you say it is ignored by default.

liayn avatar Oct 23 '21 17:10 liayn

I think we can close this issue. I think we can all agree that this library is not meant to parse @var annotations. And even if someone did convince doctrine/annotations to parse it, they would be on their own anyway.

derrabus avatar Oct 05 '22 21:10 derrabus

Thanks for bringing this on my table again. I took another look and realized that TYPO3 actually uses the Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor to retrieve the type information via PHPdoc. So closing this is perfectly fine. Thanks.

liayn avatar Oct 06 '22 09:10 liayn