Closed
Description
Symfony version(s) affected: >= 4.4
Description
DoctrineExtension#loadValidatorLoader
registers the DoctrineLoader
as a service. This class uses the Symfony\Component\Validator\Mapping\Loader\AutoMappingTrait
which might not be available.
As soon as this service gets autloaded at container build time* this will produce a fatal error under PHP8.1:
PHP Fatal error: During class fetch: Uncaught ReflectionException: Class "Symfony\Component\Validator\Mapping\Loader\AutoMappingTrait" not found while loading "Symfony\Bridge\Doctrine\Validator\DoctrineLoader`
*) one scenario is for instance reading class annotations/attributes and thereby calling $container->getReflectionClass()
How to reproduce
- Set up a Sf application with doctrine-bundle installed.
- Add a compiler pass that does the following:
foreach ($container->getDefinitions() as $definition) { $container->getReflectionClass($definition->getClass(), false); }
- Build the container.
This reminded me a bit of #32395. 🙂 Maybe we could mark the service as synthetic if the AutoMappingTrait
is not available or register a dummy instead?