Closed
Description
Symfony version(s) affected
6.3.*
Description
This is a close-to-absurd edge case, but still it occurred in my project so I report it.
When fetching a service from the service container that is public, non-shared, and lazy, twice (!), the following exception is thrown:
Symfony\Component\DependencyInjection\Container::get(): Return value must be of type ?object, string returned
On Symfony 6.2 or earlier versions, this exception was not thrown. It also doesn't seem to occur if the service is injected in a constructor instead of being pulled from the container.
Thank you for a look!
How to reproduce
Define a service as follows:
App\Service\SomeService:
public: true
shared: false
lazy: true
Then fetch it from the service container twice:
$this->container->get(SomeService::class);
$this->container->get(SomeService::class);
Possible Solution
No response
Additional Context
The problem occurs in the container's factory method for SomeService
. On the second call, $lazyLoad
contains the service ID instead of the service instance.