symfony: [DI] Random failures when autowiring classes

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.3

I’m upgrading a real application to Symfony 3.3 + Flex + autowiring. I’m using the default app.yaml config with full autowiring. The problem is that autowiring “randomly” fails.

Yesterday, I saw this error:

Expected to find class "App\Controller\AdminController" in file "/Users/javier/<my-
project>/src/Controller/AdminController.php" while importing services from resource
"../../src/*", but it was not found! Check the namespace prefix used with the
resource in /Users/javier/<my-project>/config/packages/app.yaml (which is loaded
in resource "/Users/javier/<my-project>/config/packages/app.yaml").

I’ve checked 100 times: the class exists in that file. Moreover, there are more than 10 controllers in the same location with the same namespace. All of them work, except this one.

Then I removed that AdminController, but I saw this:

Expected to find class "App\Test\AbstractTestCase" in file "/Users/javier/<my-
project>/src/Test/AbstractTestCase.php" while importing services from resource
"../../src/*", but it was not found! Check the namespace prefix used with the
resource in /Users/javier/<my-project>/config/packages/app.yaml (which is loaded
in resource "/Users/javier/<my-project>/config/packages/app.yaml").

Again, I’ve checked 100 times. Everything is correct … but it fails. If I remove that PHP class, the application works perfectly. At least with Symfony 3.3.4.


Today I’ve just upgraded the application to 3.3.5 … and I see this error message:

Expected to find class "App\Form\Type\AcmeType" in file "/Users/javier/<my-
project>/src/Form/Type/AcmeType.php" while importing services from resource
"../../src/*", but it was not found! Check the namespace prefix used with the
resource in /Users/javier/<my-project>/config/packages/app.yaml (which is loaded
in resource "/Users/javier/<my-project>/config/packages/app.yaml").

If I remove that class (which is perfectly fine, including the namespace, and yesterday it worked) the application works again.


I’m sorry I can’t give you a better error report, but this is all I know for now: autowiring randomly fails for some classes and makes the app unusable.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@sroze : it’s my mistake, i use optimize autoload and classmap authoritative by default, so when i adding new class, i need to rebuild autoload, so i removed