-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | Not sure |
RFC? | no |
Symfony version | 3.3.0 |
It seems autowiring tries to auto create the dependencies for a service before checking that the service is actually used.
It seems like it should not attempt to retrieve a dependency for a service which isn't used. If this error is actually expected or a limitation of the system, then I think there should be at least a note in the documentation, both in the autowiring doc and in the upgrade guide.
For my actual use case, I have a data class which is used as a form data object. The constructor for this class takes a service which I directly pass to it where I instantiate the object. Autowiring tries to find this service during container compile and fails.
Steps to reproduce
- Create new 3.3 app
symfony new test-app 3.3
- Add new
src/AppBundle/Class1
andsrc/AppBundle/Class2
with source as below. - Run app (
php bin/console server:start
) - Open webpage to error
Error
AutowiringFailedException
Cannot autowire service "AppBundle\Services\DataThings\OtherData": argument "$data" of method "__construct()" must have a type-hint or be given a value explicitly.
Class1 source
<?php
namespace AppBundle;
class Class1
{
public function __construct(Class2 $c2)
{}
}
Class2 source
<?php
namespace AppBundle;
class Class2
{
public function __construct($something)
{}
}