symfony: Cannot declare class Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory, because the name is already in use
Symfony version(s) affected: 5.2.1 PHP version: 7.4
Description
I use Symfony/messenger component with DoctrineTransport.
It works great in the dev environment, but I’m getting this error in the prod environment when I want to dispatch a message.
Warning: Cannot declare class Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory, because the name is already in use
I tried to trace it, and it seems it’s because of preload functionality in php7.4, and somehow after cache generation, the DoctrineTransportFactory
class was included twice.
Additional context
Sentry log:
https://sentry.io/share/issue/63ed6759822349c4b991b9ea8fc4ab14/
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 12
- Comments: 17 (14 by maintainers)
Commits related to this issue
- bug #41549 [Security] Fix opcache preload with alias classes (jderusse) This PR was merged into the 4.4 branch. Discussion ---------- [Security] Fix opcache preload with alias classes | Q ... — committed to symfony/symfony by nicolas-grekas 3 years ago
- minor #41550 [Messenger] Fix opcache preload with alias classes - for 5.2 (jderusse) This PR was merged into the 5.2 branch. Discussion ---------- [Messenger] Fix opcache preload with alias classes... — committed to symfony/symfony by nicolas-grekas 3 years ago
- minor #41551 [Security] Fix opcache preload with alias classes - for 5.3 (jderusse) This PR was merged into the 5.3 branch. Discussion ---------- [Security] Fix opcache preload with alias classes -... — committed to symfony/symfony by nicolas-grekas 3 years ago
@fabpot I don’t use the
symfony/symfony
package but still get the error. Could you reopen the issue please? 🙏 I am also happy to provide more information if someone can point me in the right direction. As stated above it seems to be somehow related to preloading. Can’t reproduce it without preloading enabled.I’ve got a similar error
Warning: Cannot declare class Symfony\Component\Security\Core\User\UserChecker, because the name is already in use
.The common thing with this issue is:
Minimal reproducer:
Maybe it’s a bug in PHP when preloading aliases… Fix that works for me
You should really move away from using the
symfony/symfony
package. Even if you are not using Flex, it allows to control which components you require and avoids downloading a lot of code you probably don’t need. Thesymfony/doctrine-messenger
package issue is not the only issue you can have while usingsymfony/symfony
directly.Is there any other information we could provide to help solve this issue?
Just got the same error.
EDIT: I only have the
App_KernelProdContainer.preload.php
file present. NoApp_KernelProdDebugContainer.preload.php
.@nicolas-grekas Yes, here is my preload.php file:
@deguif You may need to require the package
symfony/doctrine-messenger
explicitly if you are usingsymfony/symfony