Skip to content

[DI] Unexpected behavior when resolving arguments #21844

Closed
@Disparity

Description

@Disparity
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? yes
Symfony version *

When resolving the argument is an associative array with the parameters as keys, data may be lost if the parameters are resolved in the same value.

This occurs here because of the quiet overwrite values, when resolving parameters as keys.

IMHO there need to throw an exception, in order to avoid ambiguity.

It unnoticed during normal use, as no one will be for the same key to use different settings, but appears during automatic creation of the argument, for example through CompilerPass.

Various bundles can determine the extension of forms, using different ways to specify extended_type. For example:

parameters:
  param1: FormType
  param2: FormType

services:
  extension1:
    tags:
      - { name: form.type_extension, extended_type: "%param1%" }

  extension2:
    tags:
      - { name: form.type_extension, extended_type: "%param2%" }

This specifies 2 extensions, which then collects FormPass and transforms into an array:

array(
  "%param1%" => array("@service1"),
  "%param2%" => array("@service2"),
)

and then, the DI component, this argument resolves to the array:

array(
  "FormType" => array("@service2"),
)

resulting in a loss of all extensions(only specific FormType), except for the last one!

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