AnnotationReader unable to parse annotations if the comment field contains an accented character (é, è, ...) #7032

Closed
opened 2026-01-22 15:43:27 +01:00 by admin · 6 comments
Owner

Originally created by @jkazal on GitHub (Aug 31, 2022).

Bug Report

Q A
BC Break no
Version 2.9.6

Summary

Sometimes AnnotationReader fails to parse the annotations of a given class, if that class's entity definition contains PHPDoc comments that include accented characters.

I am filing this as a bug report rather than an upgrade issue because I don't know if it did the same thing before the upgrade as the bug scenario wasn't applicable previously.

Current behavior

After upgrading my VM to PHP 7.4, Doctrine returned errors like this for every entity:

class "Site\Entities\MyEntity" sub class of "Repo\Entity" is not a valid entity or mapped super class. 

However both classes had the correct annotations, but debugging showed me that Doctrine's AnnotationReader failed to get the annotations from my MyEntity class.

After debugging for some time I finally found the source of the problem:

/**
 * class my_entity
 *
 * @ORM\Entity
 * @ORM\Table(name="....")
 *
 * @author John La classe hérite de \Repo\Entity
 */

AnnotationReader was unable to read the annotations Entity and Table because of the accented character in hérite. By changing it to a normal e, I can get the annotations just fine.

I imagine this is unintended.

How to reproduce

See above

For the sake of information, my entity class files are encoded in windows-1252.

Expected behavior

I think having PHPDoc comments like @author that contain accented characters should not impact the way AnnotationReader parses a class's annotation.

Originally created by @jkazal on GitHub (Aug 31, 2022). ### Bug Report | Q | A |------------ | ------ | BC Break | no | Version | 2.9.6 #### Summary Sometimes `AnnotationReader` fails to parse the annotations of a given class, if that class's entity definition contains PHPDoc comments that include accented characters. I am filing this as a bug report rather than an upgrade issue because I don't know if it did the same thing before the upgrade as the bug scenario wasn't applicable previously. #### Current behavior After upgrading my VM to PHP 7.4, Doctrine returned errors like this for every entity: ``` class "Site\Entities\MyEntity" sub class of "Repo\Entity" is not a valid entity or mapped super class. ``` However both classes had the correct annotations, but debugging showed me that Doctrine's `AnnotationReader` failed to get the annotations from my `MyEntity` class. After debugging for some time I finally found the source of the problem: ``` /** * class my_entity * * @ORM\Entity * @ORM\Table(name="....") * * @author John La classe hérite de \Repo\Entity */ ``` `AnnotationReader` was unable to read the annotations `Entity` and `Table` because of the accented character in `hérite`. By changing it to a normal `e`, I can get the annotations just fine. I imagine this is unintended. #### How to reproduce See above For the sake of information, my entity class files are encoded in `windows-1252`. #### Expected behavior I think having PHPDoc comments like `@author` that contain accented characters should not impact the way `AnnotationReader` parses a class's annotation.
admin closed this issue 2026-01-22 15:43:27 +01:00
Author
Owner

@greg0ire commented on GitHub (Aug 31, 2022):

Can you please post a stack trace?

@greg0ire commented on GitHub (Aug 31, 2022): Can you please post a [stack trace](https://symfony.com/doc/current/contributing/code/stack_trace.html)?
Author
Owner

@jkazal commented on GitHub (Aug 31, 2022):

I'm not using Symfony so I can't give you a Symfony stack trace. I can give you the Fatal Error trace:

Fatal error: Uncaught Doctrine\ORM\Mapping\MappingException: Class "LIB\MyLibrary\Entities\library" sub class of "DBAL\Entity" is not a valid entity or mapped super class. in /doctrine-directory/Mapping/MappingException.php:371 

Stack trace: 
#0 /doctrine-directory/Mapping/Driver/AnnotationDriver.php(101): Doctrine\ORM\Mapping\MappingException::classIsNotAValidEntityOrMappedSuperClass('LIB\\MyLib...')
#1 /doctrine-directory/Mapping/ClassMetadataFactory.php(144): Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass('LIB\\MyLib...', Object(Doctrine\ORM\Mapping\ClassMetadata)) 
#2 in /doctrine-directory/Mapping/MappingException.php on line 371
@jkazal commented on GitHub (Aug 31, 2022): I'm not using Symfony so I can't give you a Symfony stack trace. I can give you the Fatal Error trace: ``` Fatal error: Uncaught Doctrine\ORM\Mapping\MappingException: Class "LIB\MyLibrary\Entities\library" sub class of "DBAL\Entity" is not a valid entity or mapped super class. in /doctrine-directory/Mapping/MappingException.php:371 Stack trace: #0 /doctrine-directory/Mapping/Driver/AnnotationDriver.php(101): Doctrine\ORM\Mapping\MappingException::classIsNotAValidEntityOrMappedSuperClass('LIB\\MyLib...') #1 /doctrine-directory/Mapping/ClassMetadataFactory.php(144): Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass('LIB\\MyLib...', Object(Doctrine\ORM\Mapping\ClassMetadata)) #2 in /doctrine-directory/Mapping/MappingException.php on line 371 ```
Author
Owner

@jkazal commented on GitHub (Aug 31, 2022):

In addition, it seems the issue is fixed by switching the class file encoding to UTF-8 for the affected Entities.

@jkazal commented on GitHub (Aug 31, 2022): In addition, it seems the issue is fixed by switching the class file encoding to UTF-8 for the affected Entities.
Author
Owner

@derrabus commented on GitHub (Aug 31, 2022):

Well, what encoding did you use previously? That would be an important piece of information to track down the issue. That being said, I'm not really keen on fixing the Doctrine Annotations library for non-UTF-8 encodings.

@derrabus commented on GitHub (Aug 31, 2022): Well, what encoding did you use previously? That would be an important piece of information to track down the issue. That being said, I'm not really keen on fixing the Doctrine Annotations library for non-UTF-8 encodings.
Author
Owner

@jkazal commented on GitHub (Aug 31, 2022):

As mentioned in the OP:

For the sake of information, my entity class files are encoded in windows-1252.

That being said, if UTF8 is the only encoding supported by Doctrine Annotations that's also fine, however I couldn't find any info regarding that. Feel free to close the issue if that's the case

@jkazal commented on GitHub (Aug 31, 2022): As mentioned in the OP: > For the sake of information, my entity class files are encoded in windows-1252. That being said, if UTF8 is the only encoding supported by Doctrine Annotations that's also fine, however I couldn't find any info regarding that. Feel free to close the issue if that's the case
Author
Owner

@derrabus commented on GitHub (Aug 31, 2022):

As mentioned in the OP:

For the sake of information, my entity class files are encoded in windows-1252.

Oh sorry, I missed that. 🙈

That being said, if UTF8 is the only encoding supported by Doctrine Annotations that's also fine, however I couldn't find any info regarding that. Feel free to close the issue if that's the case

If converting those files to UTF-8 works for you, I'd be in favor of closing the issue. Doctrine Annotations don't have a bright future, now that PHP has native attributes. Fixing this issue is probably not worth the effort.

@derrabus commented on GitHub (Aug 31, 2022): > As mentioned in the OP: > > > For the sake of information, my entity class files are encoded in windows-1252. Oh sorry, I missed that. 🙈 > That being said, if UTF8 is the only encoding supported by Doctrine Annotations that's also fine, however I couldn't find any info regarding that. Feel free to close the issue if that's the case If converting those files to UTF-8 works for you, I'd be in favor of closing the issue. Doctrine Annotations don't have a bright future, now that PHP has native attributes. Fixing this issue is probably not worth the effort.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7032