Skip to content

default_index_method mishandles "numeric" strings #35349

@Bilge

Description

@Bilge

Symfony version(s) affected: 4.4.0

Description
Creating a tagged locator with default_index_method set to a method name returning numbers encoded as strings (e.g. "123"), does not work. It reindexes each entry as a numerical list starting from 0 instead of using the values supplied by the index method.

How to reproduce

services:
    _instanceof:
        My\Service:
            tags: [foo]

    My\ServiceAggregator:
        arguments:
            $foos: !tagged_locator { tag: foo, default_index_method: getId }

Additional context
Debugging shows My\Service::getId is actually called at container creation time, and it receives the correct value, but ends up discarding it at some point. That point is exactly here, where it does an array_merge, which according to the docs:

Values in the input arrays with numeric keys will be renumbered with incrementing keys starting from zero in the result array.

This is the beaviour I'm seeing.

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