Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fetching of lazy non-shared services sometimes broken #50975

Copy link
Copy link
Closed
@umulmrum

Description

@umulmrum
Issue body actions

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.