php - application level error after symfony update to 3.4


today i upgraded from sf2.8 to sf3.4... first i faced some errors because i did not reworked the sf standard files, now these errors are gone and i'm stuck with an error on application level. under sf2.8 it was not an issue and tbh i dont understand why its now.

error triggered hitting "/":

[Tue Oct 02 11:37:31.885382 2018] [proxy_fcgi:error] [pid 24:tid 140202295097088] [client] AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Symfony\\Component\\Debug\\Exception\\FatalThrowableError: Type error: Argument 2 passed to TheApp\\FrontendBundle\\Services\\UrlAliasService::__construct() must be an instance of TheApp\\FrontendBundle\\Routing\\Router, instance of Symfony\\Bundle\\FrameworkBundle\\Routing\\Router given, called in /var/www/var/cache/dev/ContainerV5bxhc0/appDevDebugProjectContainer.php on line 3678 in /var/www/src/TheApp/FrontendBundle/Services/UrlAliasService.php:25\nStack trace:\n#0 /var/www/var/cache/dev/ContainerV5bxhc0/appDevDebugProjectContainer.php(3678): TheApp\\FrontendBundle\\Services\\UrlAliasService->__construct(Object(Doctrine\\ORM\\EntityManager), Object(Symfony\\Bundle\\FrameworkBundle\\Routing\\Router), Object(Cocur\\Slugify\\Slugify))\n#1 /var/www/var/cache/dev/ContainerV5bxhc0/appDevDebugProjectContainer.php(3698): ContainerV5bxhc0\\appDevDebugProjectContainer->getTheApp_UrlaliasserviceService()\n#2 /var/www/var/cache/dev/ContainerV5bxhc0/appDevDebugProjectContainer.php(3872): Contain...\n'

so the service "UrlAliasService" takes 3 parameters:

use TheApp\FrontendBundle\Routing\Router;
public function __construct(EntityManager $entityManager, Router $router, Slugify $slugify)
        $this->em = $entityManager;
        $this->urlRepository = $this->em->getRepository('TheAppFrontendBundle:UrlAlias');
        $this->router = $router;
        $this->slugify = $slugify;
        $this->urlAliasInProcess = new ArrayCollection();

these 3 parameters get wired in services.yml:

        class: TheApp\FrontendBundle\Services\UrlAliasService
        arguments: ["@doctrine.orm.entity_manager", "@router", "@cocur_slugify"]

here is the router class, extending BaseRouter:

namespace TheApp\FrontendBundle\Routing;

use Symfony\Bundle\FrameworkBundle\Routing\Router as BaseRouter;
use Symfony\Component\Routing\RequestContext;

class Router extends BaseRouter implements ContainerAwareInterface
    private $container;

    public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null)
        parent::__construct($container, $resource, $options, $context);

    public function getGenerator()
        $generator = parent::getGenerator();
        return $generator;

    public function setContainer(ContainerInterface $container = null)
        $this->container = $container;

so the error tells me that the argument passed in is from type TheApp\FrontendBundle\Routing\Router .... but it actually is from type Symfony\Bundle\FrameworkBundle\Routing\Router .... reading the code this error makes no sense right? the class TheApp\FrontendBundle\Routing\Router extends Symfony\Bundle\FrameworkBundle\Routing\Router so how can it be not an instance from it? help and explanation is very very much appreciated.




it's obvious that@router is a Router service defined bySymfony\Bundle\FrameworkBundle\Routing\Router. Instead of it inarguments: ["@doctrine.orm.entity_manager", "@router", "@cocur_slugify"] you should inject your service, for exampletheapp.router. You have a few choices here:

  1. declare your service astheapp.route
  2. overriderouter with your service , but I would not do it.

People are also looking for solutions to the problem: php - get all record between two dates interval in mysql


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.