Menu

← Back to symfonyContainer.*

Error Identifier: symfonyContainer.serviceNotFound

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class MyController extends AbstractController
{
    public function index(): void
    {
        $this->get('unknown_service');
    }
}

Why is it reported? #

The service identifier passed to ContainerInterface::get() does not match any service registered in the Symfony dependency injection container. This means the call will throw a ServiceNotFoundException at runtime.

PHPStan reads the compiled container configuration to know which services are available. If the service ID is not found in the compiled container, this error is reported.

This rule is provided by the phpstan-symfony package.

How to fix it #

Use a valid service identifier that is registered in the container:

 <?php declare(strict_types = 1);
 
 namespace App\Controller;

 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

 class MyController extends AbstractController
 {
     public function index(): void
     {
-        $this->get('unknown_service');
+        $this->get('app.my_service');
     }
 }

Alternatively, use constructor injection instead of fetching services from the container directly, which is the recommended approach in modern Symfony applications:

 <?php declare(strict_types = 1);
 
 namespace App\Controller;

 use App\Service\MyService;
 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

 class MyController extends AbstractController
 {
-    public function index(): void
+    public function __construct(private MyService $myService)
     {
-        $service = $this->get('app.my_service');
+    }
+
+    public function index(): void
+    {
+        $this->myService->doSomething();
     }
 }

How to ignore this error #

You can use the identifier symfonyContainer.serviceNotFound to ignore this error using a comment:

// @phpstan-ignore symfonyContainer.serviceNotFound
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: symfonyContainer.serviceNotFound

Rules that report this error #

  • PHPStan\Rules\Symfony\ContainerInterfaceUnknownServiceRule [1] phpstan/phpstan-symfony

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.