Description
Symfony version(s) affected
7.3.0
Description
After updating to Symfony 7.3 and changing my AppExtension to use attributes instead of getFilter() and getFunctions(), I receive the following error:
Twig\Environment::addExtension(): Argument #1 ($extension) must be of type Twig\Extension\ExtensionInterface, App\Twig\AppExtension given, called in (...)\var\cache\dev\ContainerIc33vwE\App_KernelDevDebugContainer.php on line 16122
The AppExtension has a __construct-method to autowire a couple of things (like EntityManager, Translator, RequestStack) which seem to make the difference as in another project without __construct in AppExtension I could switch to attributes without the error.
How to reproduce
Use a custom AppExtension with attributes and a __construct-method with
Symfony 7.3.
Possible Solution
No response
Additional Context
In the Twig-documentation (https://twig.symfony.com/doc/3.x/advanced.html) a way to use AppExtension with __construct is decribed but it initiates the extension manually which was not necessary before - is it now?
Stack trace:
in (...)\vendor\twig\twig\src\Environment.php (line 687)
Environment->addExtension(object(AppExtension))
in (...)\var\cache\dev\ContainerIc33vwE\App_KernelDevDebugContainer.php (line 16122)
App_KernelDevDebugContainer::getTwigService(object(App_KernelDevDebugContainer))
in (...)\var\cache\dev\ContainerIc33vwE\App_KernelDevDebugContainer.php (line 721)
App_KernelDevDebugContainer::get_Container_Private_ProfilerService(object(App_KernelDevDebugContainer))
in (...)\var\cache\dev\ContainerIc33vwE\App_KernelDevDebugContainer.php (line 10793)
App_KernelDevDebugContainer::getAssetMapper_DevServerSubscriberService(object(App_KernelDevDebugContainer))
in (...)\var\cache\dev\ContainerIc33vwE\App_KernelDevDebugContainer.php (line 3220)
App_KernelDevDebugContainer::{closure:ContainerIc33vwE\App_KernelDevDebugContainer::getEventDispatcherService():3220}()
in (...)\vendor\symfony\event-dispatcher\EventDispatcher.php (line 221)
EventDispatcher->sortListeners('kernel.request')
in (...)\vendor\symfony\event-dispatcher\EventDispatcher.php (line 70)
EventDispatcher->getListeners('kernel.request')
in (...)\vendor\symfony\event-dispatcher\Debug\TraceableEventDispatcher.php (line 256)
TraceableEventDispatcher->preProcess('kernel.request')
in (...)\vendor\symfony\event-dispatcher\Debug\TraceableEventDispatcher.php (line 120)
TraceableEventDispatcher->dispatch(object(RequestEvent), 'kernel.request')
in (...)\vendor\symfony\http-kernel\HttpKernel.php (line 159)
HttpKernel->handleRaw(object(Request), 1)
in (...)\vendor\symfony\http-kernel\HttpKernel.php (line 76)
HttpKernel->handle(object(Request), 1, true)
in (...)\vendor\symfony\http-kernel\Kernel.php (line 182)
Kernel->handle(object(Request))
in (...)\vendor\symfony\runtime\Runner\Symfony\HttpKernelRunner.php (line 35)
HttpKernelRunner->run()
in (...)\vendor\autoload_runtime.php (line 29)
require_once('(...)\\vendor\\autoload_runtime.php')
in (...)\public\index.php (line 6)