Skip to content

[HttpKernel] Strange controller argument behaviour #24729

Closed
@vudaltsov

Description

@vudaltsov
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.4 (maybe earlier)

With default routing and services configuration create a simple controller with a non-service class like this:

<?php

namespace App\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

class IndexController extends AbstractController
{
    /**
     * @Route(name="index")
     */
    public function indexAction(A $a)
    {
        dump($a);

        return new Response();
    }
}

class A
{
}

Expected result: an exception about wrong argument. Actual result:

image

Which means that a new instance of a non-DI class is injected.

I investigated a little and found that Symfony\Component\HttpKernel\Controller\ArgumentResolver\ServiceValueResolver does this.

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