doctrine / persistence

The Doctrine Persistence project is a library that provides common abstractions for object mapper persistence.
https://www.doctrine-project.org/projects/persistence.html
MIT License
3.95k stars 64 forks source link

Failed to retrieve the reflection object for documents with enum #350

Closed yunicot closed 8 months ago

yunicot commented 8 months ago

I am using: php 8.3.3 symfony 6.4 doctrine/mongodb-odm (v2.6.3)

When I try to dump the document with enum I get the error "Internal error: Failed to retrieve the reflection object"

Exception trace:
  at /srv/app/vendor/symfony/var-dumper/Caster/ReflectionCaster.php:344
 ReflectionProperty->getModifiers() at /srv/app/vendor/symfony/var-dumper/Caster/ReflectionCaster.php:344
 Symfony\Component\VarDumper\Caster\ReflectionCaster::castProperty() at /srv/app/vendor/symfony/var-dumper/Cloner/AbstractCloner.php:363
 Symfony\Component\VarDumper\Cloner\AbstractCloner->castObject() at /srv/app/vendor/symfony/var-dumper/Cloner/VarCloner.php:130
 Symfony\Component\VarDumper\Cloner\VarCloner->doClone() at /srv/app/vendor/symfony/var-dumper/Cloner/AbstractCloner.php:302
 Symfony\Component\VarDumper\Cloner\AbstractCloner->cloneVar() at /srv/app/vendor/symfony/http-kernel/EventListener/DumpListener.php:49
 Symfony\Component\HttpKernel\EventListener\DumpListener::Symfony\Component\HttpKernel\EventListener\{closure}() at /srv/app/vendor/symfony/var-dumper/VarDumper.php:52
 Symfony\Component\VarDumper\VarDumper::dump() at /srv/app/vendor/symfony/var-dumper/Resources/functions/dump.php:53
 dd() at /srv/app/src/DataProvider/Infrastructure/Command/MigrateRepresentativeUserToEmployeeCommand.php:37
 App\DataProvider\Infrastructure\Command\MigrateRepresentativeUserToEmployeeCommand->execute() at /srv/app/vendor/symfony/console/Command/Command.php:326
 Symfony\Component\Console\Command\Command->run() at /srv/app/vendor/symfony/console/Application.php:1096
 Symfony\Component\Console\Application->doRunCommand() at /srv/app/vendor/symfony/framework-bundle/Console/Application.php:126
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /srv/app/vendor/symfony/console/Application.php:324
 Symfony\Component\Console\Application->doRun() at /srv/app/vendor/symfony/framework-bundle/Console/Application.php:80
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /srv/app/vendor/symfony/console/Application.php:175
 Symfony\Component\Console\Application->run() at /srv/app/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49
 Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /srv/app/vendor/autoload_runtime.php:29
 require_once() at /srv/app/bin/console:13

After small research I found that the problem can be solved if add to EnumReflectionProperty next code:

    public function getModifiers(): int
    {
        return $this->originalReflectionProperty->getModifiers();
    }

    public function getDocComment(): string|false
    {
        return $this->originalReflectionProperty->getDocComment();
    }

I had this problem and before during at least 1 year, but it wasn't critical and just delayed to solving

derrabus commented 8 months ago

Please send a PR that adds those.