Skip to content

[DependencyInjection] Service locator: services not indexed by their service ID anymore by default #61008

Closed as not planned
@bicpi

Description

@bicpi

Symfony version(s) affected

7.3.1

Description

After updating the DependencyInjection component from 7.3.0 to 7.3.1, the service locator used in our code base started to fail because services are not indexed by service ID anymore but by a numeric index. Downgrading to 7.3.0 restores the behavior.

This may be caused by #60691?

The change can be seen in the serviceMap property of the Symfony\Component\DependencyInjection\ServiceLocator; in 7.3.0 we see the services being indexes by service ID, as expected by default

By default, services passed to the service locator are indexed using their service IDs.

https://symfony.com/doc/current/service_container/service_subscribers_locators.html#indexing-the-collection-of-services

Starting with Symfony 7.3.1, the serviceMap is index numerically, so the has($serviceId) and get($serviceId) methods cannot find the services anymore.

Our services config uses a tagged iterator to set up the service locator which worked fine for quite a while and up until 7.3.0:

  foo_locator:
    class: Symfony\Component\DependencyInjection\ServiceLocator
    arguments:
      - !tagged_iterator foo_tag

Services tagged with foo_tag are now ending up with a numeric index in the service locator instead of getting indexed by their service ID.

How to reproduce

Set up service locator and some services with the foo_tag:

  foo_locator:
    class: Symfony\Component\DependencyInjection\ServiceLocator
    arguments:
      - !tagged_iterator foo_tag

Check the service locator - services cannot be found by service ID in 7.3.1 anymore while that works in 7.3.0.

Possible Solution

No response

Additional Context

No response

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