Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine

Upgrade to Symfony 3.4

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

Symfony 4: it's a game changer. It's my favorite thing since chocolate milk. Honestly, I've never been so excited to start writing tutorials: you are going to love it!

But first, we need to talk about how you can upgrade to Symfony 4 so that all your projects can enjoy the goodness!

There are two big steps. First, well, of course, we need to actually upgrade our app to Symfony 4! And second, we need to update our project to support Symfony Flex. That is where things get interesting.

Upgrading does take some work. But don't worry: we'll walk through it together and learn a ton on the way.

Download the Course Code

As always, if you really want to get a handle on upgrading... or you just like chocolate milk, you should download the course code from this page and code along. Full disclosure: the download does not contain chocolate milk.

But, after you unzip it, it does contain a start/ directory with the same code you see here. Follow the README.md file for the steps needed to get your project running.

The last step will be to find your terminal and run:

./bin/console server:run

to start the built-in web server. Check it out at http://localhost:8000. Hello AquaNote! This is the Symfony 3.3 project that we've been building in our Symfony series.

Upgrading to Symfony 4

So: what's the first step to upgrading to Symfony 4? It's upgrading to 3.4! And that's delighyfully simple: Open composer.json, change the version of symfony/symfony to ^3.4, find your terminal and run:

68 lines composer.json
... lines 1 - 15
"require": {
... line 17
"symfony/symfony": "^3.4",
... lines 19 - 30
... lines 32 - 68
composer update

And celebrate! So easy! By the way, you could just update symfony/symfony. But, honestly, it's just easier to upgrade everything. And since I keep responsible version constraints in composer.json, ahem, no dev-master or * versions, this is pretty safe and also means I get bug fixes, security fixes and new features.

And... hello Symfony 3.4! The best part? Ah, you guys already know it: thanks to Symfony's backwards-compatibility promise, our project will just work... immediately. Refresh! Yep! Welcome to Symfony 3.4.

Symfony 3.4 Versus Symfony 4.0

So why did we do this? Why not just skip directly to Symfony 4? Well, Symfony 3.4 and Symfony 4.0 are identical: they have the exact same features. The only difference is that all deprecated code paths are removed in 4.0.

On the web debug toolbar, you can see that this page contains 9 deprecated code calls. By upgrading to Symfony 3.4 first, we can hunt around and fix these. As soon as they're all gone... well, we'll be ready for Symfony 4!

Deprecation: Kernel::loadClassCache()

Click the icon to go see the full list of deprecations. Check out the first one: Kernel::loadClassCache() is deprecated since version 3.3. You can click "Show Trace" to see where this is coming from, but I already know!

Open web/app.php and web/app_dev.php. There it is! On line 28, remove the $kernel->loadClassCache() line. Do the same thing in app.php. Why is this deprecated? This originally gave your app a performance boost. But thanks to optimizations in PHP 7, it's not needed anymore. Less code, more speed, woo!

Deprecation: GuardAuthenticator::supports()

Close those files. What's next? Hmm, something about AbstractGuardAuthenticator::supports() is deprecated. Oh, and a recommendation! We should implement supports() inside our LoginFormAuthenticator.

Because I obsess over Symfony's development, I know what this is talking about. If you have more of a life than I do and are not already aware of every single little change, you should go to github.com/symfony/symfony and find the UPGRADE-4.0.md file. It's not perfect, but it contains explanations behind a lot of the changes and deprecations you'll see.

Go find the LoginFormAuthenticator in src/AppBundle/Security. We need to add a new method: public function supports() with a Request argument.

Copy the logic from getCredentials() that checks the URL, and just return it. Here's the deal: in Symfony 3, getCredentials() was called on every request. If it returned null, the authenticator was done: no other methods were called on it.

... lines 1 - 15
class LoginFormAuthenticator extends AbstractFormLoginAuthenticator
... lines 18 - 30
public function supports(Request $request)
return $request->getPathInfo() == '/login' && $request->isMethod('POST');
... line 35
public function getCredentials(Request $request)
... lines 38 - 47
... lines 49 - 77

In Symfony 4, supports() is now called on every request instead. If it returns false, the authenticator is done like before. But if it returns true, then getCredentials() is called. We split the work of getCredentials() into two methods.

So, remove the logic at the top of it: we know this will only be called when the URL is /login and it's a POST request.

Deprecation: Quoting % in YAML

Most of the other deprecations are pretty easy, like the next one:

Not quoting the scalar %cache_type% starting with the "%" indicator character is deprecated since Symfony 3.1.

This, and the next deprecation are in config.yml - and it even tells us the exact lines!

Open up app/config/config.yml and find line 71. Yep! Put quotes around %cache_type%. To more closely follow the official YAML spec, if a value starts with %, it needs to have quotes around it. Do the same around the directory value.

... lines 1 - 67
type: '%cache_type%'
directory: '%kernel.cache_dir%/markdown_cache'
... lines 74 - 80

Deprecation: logout_on_user_change

Back on the list, there is one more easy deprecation!

Not setting logout_on_user_change to true on firewall "main" is deprecated as of 3.4.

Copy that key. Then, open app/config/security.yml. Under the main firewall, paste this and set it to true.

... lines 1 - 14
... lines 16 - 20
... lines 22 - 29
logout_on_user_change: true
... lines 31 - 41

So, what the heck is this? Check it out: suppose you change your password while on your work computer. Previously, doing that did not cause you to be logged out on any other computers, like on your home computer. This was a security flaw, and the behavior was changed in Symfony 4. By turning this on, you can test to make sure your app doesn't have any surprises with that behavior.

Phew! Before we talk about the last deprecations, go back to the homepage and refresh. Yes! In 5 minutes our 9 deprecations are down to 2! Open up the list again. Interesting: it says:

Relying on service auto-registration for Genus is deprecated. Create a service named AppBundle\Entity\Genus instead.

That's weird... and involves changes to autowiring. Let's talk about those next!

Leave a comment!

Login or Register to join the conversation
Default user avatar
Default user avatar Sara Mohamed | posted 2 years ago | edited

I have followed the step that you provided to migrate from 3.3 to 3.4 but after I updated I am facing and issue now with AuthorizationChecker which fails when its trying to do isGranted() and returns an error:
Uncaught PHP Exception Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException: "The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL."
but before the migration everything was working fine :(
any ideas why the checks failing only after migration.


Hey @Sara!

Sorry for the slow reply - this was a tough issue, so it was left for me to do my best!

Ok, so this is interesting. I would not have expected simply upgrading from 3.3 to 3.4 to cause this. The error, as it says, typically means that the URL you are going to is not "under" a firewall. But what I can't imagine is why this would have changed going from 3.3 to 3.4.

What does your firewalls config look like for your security?


Leila A. Avatar
Leila A. Avatar Leila A. | posted 2 years ago

Hi what do I do after receiving this error message when trying to do php bin/console doctrine:database:create?.
PHP Warning: require(/.../start/app/../vendor/autoload.php): Failed to open stream: No such file or directory in /.../start/app/autoload.php on line 11
PHP Fatal error: Uncaught Error: Failed opening required '/.../start/app/../vendor/autoload.php' (include_path='.:/usr/share/php') in /.../start/app/autoload.php:11
Stack trace:
#0 /.../start/bin/console(17): require()
#1 {main}
thrown in /.../start/app/autoload.php on line 11

thank you for your help


Hey @Leilani!

That's no fun! Sorry about the trouble :). But, I know this error! Make sure you first run:

 composer install

I believe that's all you're missing: you need this to populate your vendor/ directory. It should be mentioned in the README.md file in the code download - but let me know if you didn't find it.


Oumaima B. Avatar
Oumaima B. Avatar Oumaima B. | posted 3 years ago

hello i really have a big problem with my application and i would love some help
Please halp!


Hey @oumaima

Can you provide more details? What problem? What application? We will be glad to help you!


Default user avatar

just a quick question: how do I update the new directory structure? I did not have a public folder with Symfony 3.4, it seems I need it with Symfony 4.0.




Hey mario

In symfony 4, the web directory got renamed to public but everything else is almost the same (inside that directory)


Default user avatar

thanks for your reply.
Sorry, I did not explain myself. My 3.4 directory is:

├── app
│ ├── AppCache.php
│ ├── AppKernel.php
│ ├── autoload.php
│ ├── config
│ │ ├── ...
│ └── Resources
│ ├── Public
│ └── views
├── bin
│ ├── console
│ ├── php_errors.log
│ └── symfony_requirements
├── composer.json
├── composer.lock
├──. ...
├── src
│ └── MyBundle
│ ├── BlogBundle (a custom bundle)
│ │ ├── Controller
│ │ ├── DependencyInjection
│ │ ├── Entity
│ │ ├── Form
│ │ ├── JusBlogBundle.php
│ │ ├── Repository
│ │ ├── Resources (most view and public stuff is within these directories, for each bundle)

│ │ └── Tests
│ ├── ... several more bundles
├── var
│ ├── ...
├── vendor
│ ├── ...
└── web
├── ...
├── bundles
│ ├── jusblog -> ../../src/Jus/BlogBundle/Resources/public/
│ ├── ... several more symlinks
├── config.php

I modify composer.json, and >composer update; seems to work fine. But my web app does not work any more, since the directory structure remains the old one. I am not sure what the guideline are to move things around as to define the new structure.

Thanks Cheers

1 Reply

Yeah, the structure changed considerably in Symfony4 and it's a manual process. If you keep watching the tutorial you will learn how Ryan handled it (and, of course, you can keep asking us questions :)


CDesign Avatar
CDesign Avatar CDesign | posted 4 years ago | edited

It's probably worth noting that as of Twig 2.7 (roughly Mar 2019), users will get an additional deprecation warning after updating to Symfony 3.4:

Using the "Twig_Extension" class is deprecated since Twig version 2.7, use "Twig\Extension\AbstractExtension" instead

I don't think this affects anything else in the tutorial, however, since twig's deprecations (and development path) are independent of symfony's.


Hey John christensen

You are right, Twig deprecations are other thing to consider but it has nothing to do with Symfony. You could even start a new Symfony project without Twig :)


Tobias I. Avatar
Tobias I. Avatar Tobias I. | posted 5 years ago


You mentioned in the video that version 3.4 and 4 are identical. https://symfony.com/doc/cur... on this page from the symfony docs it says that symfony 4.0 requires PHP version 7.1.3 or higher. So as I understand, symfony 3.4 also requires at minimum PHP 7.1.3, correct? I am asking because the hosting I eventually want to deploy to can only run PHP 7.1.1 at this moment and upgrading to a higher version will not be possible for some time, maybe 6 months to a year.
I intended to start developing on symfony 3.4 and eventually upgrade to 4, because this page from the docs states that 3.4 only requires PHP 5.5.9 to run: https://symfony.com/doc/3.4...

I am a bit confused I must say :(


Hey Tobias I.

In the video, Ryan was talking about Symfony's behavior but as you already investigated, Symfony4 requires PHP >=7.1.3 in order to work, so if you really can't upgrade to that version, then you should stick with Symfony 3.4 and eventually do the upgrade

Here you can see all the requirements of Symfony3.4 https://github.com/symfony/...


Tobias I. Avatar

Thanks for clarifying.
Have an awesome day :)

Shing S. Avatar
Shing S. Avatar Shing S. | posted 5 years ago


"But thanks to optimizations in PHP 7, it's not needed anymore. Less code, more speed, woo!"
Whats r the optimisations in php7 that dont require loadCacheClasses.

Thanks in advance



Great question! And actually, I wasn't sure myself :). So, I did some digging. Here is the source: https://github.com/symfony/...

It appears that the optimizations were more related to the Composer optimized autoloader & OpCache. That issue doesn't mention the exact things in PHP 7 that really allowed this. So, unfortunately, I can't answer that question fully. A lot was optimized in PHP 7, so it could have been a number of things.


Shing S. Avatar

Cool, I see now. I should have check why $kernel->loadClassCache() exist in the 1st place.

If anyone is interested. In the docs https://symfony.com/blog/ne....

It says
"Symfony provides three autoloaders via the ClassLoader component: two of them load classes that follow PSR-0 and PSR-4 standards and the other one uses a static map of classes and files. In addition, Symfony provides special wrappers for those loaders to add caching and debugging features."

So i guess previous to symfony 4, it reorders ur code and stores it in var/cache, so that it loads properly, then bring it to opcache as precompiled script. In symfony 4 it goes straight to opcache. I think this is right?

thanks for taking the time

Default user avatar
Default user avatar J.R. Jenkins | posted 5 years ago

Besides upgrading to PHP 7, what would you recommend people who are stuck on PHP 5.5.9 do in regards to the ```Kernel::loadClassCache()``` call? For internal reasons we have several apps that are still on Ubuntu 14.04 LTS versions and the systems administrators prefer to install PHP via APT, so we are limited on upgrading. I see that it looks like in a new Symfony 3.4 install they wrap this in a ```if (PHP_VERSION_ID < 70000) {}``` block, but I still had errors when I tried to load with that. Any recommendations?


Hey J.R. Jenkins!

Ah, stuck on PHP 5 - I understand it, but bummer! So, if you're stuck on PHP 5, then you're also stuck in Symfony 3.4 for now. This basically means that, until you're ready to upgrade to Symfony 4, you should just ignore the loadClassCache() stuff (i.e. LEAVE them - don't remove them). You mentioned you're having "errors" - you should only have deprecation warnings. Are you getting actual errors with loadClassCache()?


1 Reply
Default user avatar
Default user avatar J.R. Jenkins | weaverryan | posted 5 years ago | edited

weaverryan I did get an error, although I will have to look it up when I get back to work in the morning, that actually led me to this discussion in the Symfony issue queue, https://github.com/symfony/.... Basically I had started with a 3.4 install and was slowly developing things out, but when trying to access the site through app.php it would crash with what I believe was the "Cannot redeclare class Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser" error

Commenting out both the include for bootstrap.php and call to loadClassCache resolved the issue, but that didn't seem right. I was going to dig into when I saw you were releasing this course so I thought I would see what you all had to say :-)

Default user avatar

So I am apparently crazy or had some other bug that I didn't realize, as I uncommented those lines, cleared my caches, and there is no error... sorry for the red herring.


Ah yes, you started a new project - I'm aware of that bug you linked to. But, I'm glad it's working now - I'm not sure if your code contains that fix or not - but I wouldn't worry about it unless it comes up again :).


Default user avatar

Hi weaverryan,

I install the a fresh symfony 4 with composer create-project symfony/skeleton
Everything seems to be ok. So I want to install all components. The symfony site (https://symfony.com/doc/cur... says to composer require symfony/symfony

I get an error
Your requirements could not be resolved to an installable set of packages.
Problem 1
- symfony/symfony v4.0.0 conflicts with __root__[No version set (parsed as 1.0.0)].
- symfony/symfony v4.0.1 conflicts with __root__[No version set (parsed as 1.0.0)].
- symfony/symfony v4.0.2 conflicts with __root__[No version set (parsed as 1.0.0)].
- Installation request for __root__ No version set (parsed as 1.0.0) -> satisfiable by __root__[No version set (parsed as 1.0.0)].
- Installation request for symfony/symfony ^4.0 -> satisfiable by symfony/symfony[v4.0.0, v4.0.1, v4.0.2].

My composer is of the latest version 1.5.6

Am I doing something wrong?


Hey Shing,

Good catch! Actually, it's impossible to require symfony/symfony due to this line: https://github.com/symfony/... . As you can see, it forbids installation of symfony/symfony. I'm not sure about the reasons behind, but I think it's kind of bug in Symfony docs. I opened an issue about it here: https://github.com/symfony/...

So, the only way I see is to install all the deps manually obviously specifying them in composer.json. Actually, it's not a best practice to install all the Symfony components to your project when you don't use them *all*. And probably in most cases you won't use them all :)


Default user avatar

Hi Victor, Glad I know I'm not mad. I'm rather new at this. I guess documentation might not always be accurate. Also the change from symfony 3 to 4 does not seem trival.

Thanks for help :)


Hey Shing,

I agree, it's not trivial, but that's the price to increase code quality and make development more smooth. However, Symfony devs made all their best to make this upgrading process very smooth, thanks to cool deprecation notices feature.


Default user avatar
Default user avatar Nan Zhao | posted 5 years ago

In the lastest version of symfony3, the config.yml is not generated by using 'composer create-project symfony/skeleton 3.4'. I tried to load the file "doctrine_cache.yaml", but failed. When I type 'php ./bin/console dubug:container markdown_cache', the command line says 'In ContainerDebugCommand.php line 211: No services found that match "markdown_cache". How can I create a custom server? Can you help me ?


Hey Nan,

You're right, there's no config.yml anymore, it was splitted to separate files, that's why you need to create it "doctrine_cache.yaml" file manually inside "config/packages/". Actually, this question is duplicated, so look at my original answer:


Dan_M Avatar

Hey guys,

I had a working site at version 3.3.16. When I upgraded to 3.4 by changing the version number in composer.json and executing composer update, I got the following cryptic error message: "Circular reference detected for service "routing.loader", path: "routing.loader".

How do I find and fix that problem?


Hey Dan,

Sometimes upgrading is a bit tricker than just Symfony constraint tweaking to 3.4. First of all, try to compare the original composer.json file for 3.4 branch and tweak other constraints of core deps as well according to it: https://github.com/symfony/...

Also, try to manually remove folders from var/cache/* like dev/, prod/, test/, etc.

Then run composer update again, probably it helps. If not, try to make the output more verbose with:
composer update -vvv

It should give you more context to find the root of the problem. If you still cannot handle it - show us the verbose output with "-vvv" option and we'll try to help you.


Dan_M Avatar
Dan_M Avatar Dan_M | Victor | posted 5 years ago | edited


I followed those steps to no avail. I even cleared my composer cache and made it download all the packages again. No joy there either.

I hope the following is enough information for you to see something I don't.

Here's an excerpt from my composer.json file:

    "require": {
        "php": "^5.5.9|>=7.0.8",
        "behat/behat": "^3.4",
        "behat/mink-extension": "^2.2",
        "behat/mink-goutte-driver": "^1.2",
        "behat/mink-selenium2-driver": "^1.3",
        "braincrafted/bootstrap-bundle": "^2.2",
        "components/jquery": "^3.2",
        "doctrine/data-fixtures": "^1.2",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/doctrine-cache-bundle": "^1.3",
        "doctrine/doctrine-fixtures-bundle": "^2.4",
        "doctrine/doctrine-migrations-bundle": "^1.2",
        "doctrine/orm": "^2.5",
        "easycorp/easyadmin-bundle": "^1.17",
        "egeloen/ckeditor-bundle": "^6.0",
        "friendsofsymfony/jsrouting-bundle": "^1.6",
        "friendsofsymfony/user-bundle": "^2.0",
        "gedmo/doctrine-extensions": "^2.4",
        "guzzlehttp/guzzle": "^6.3",
        "incenteev/composer-parameter-handler": "^2.0",
        "knplabs/knp-markdown-bundle": "^1.5",
        "knplabs/knp-paginator-bundle": "^2.6",
        "nelmio/cors-bundle": "^1.5",
        "sensio/distribution-bundle": "^5.0.19",
        "sensio/framework-extra-bundle": "^5.0.0",
        "sonata-project/admin-bundle": "^3.18",
        "sonata-project/core-bundle": "^3.4",
        "sonata-project/doctrine-orm-admin-bundle": "^3.1",
        "stof/doctrine-extensions-bundle": "^1.2",
        "symfony/assetic-bundle": "^2.8",
        "symfony/monolog-bundle": "^3.1.0",
        "symfony/polyfill-apcu": "^1.0",
        "symfony/serializer": "^3.3",
        "symfony/swiftmailer-bundle": "^2.3.10",
        "symfony/symfony": "^3.4",
        "twbs/bootstrap": "^3.3",
        "twig/twig": "^1.0||^2.0",
        "vich/uploader-bundle": "^1.7"
    "require-dev": {
        "hautelook/alice-bundle": "^1.4",
        "liip/functional-test-bundle": "^1.8",
        "phpunit/dbunit": "^2.0",
        "phpunit/phpunit": "^5.7",
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^3.0"

When I do composer update -vvv, I get this response:

Resolving dependencies through SAT
Dependency resolution completed in 4.433 seconds
Analyzed 20318 packages to resolve dependencies
Analyzed 2682107 rules to resolve dependencies
Resolving dependencies through SAT
Dependency resolution completed in 0.001 seconds
Package operations: 0 installs, 2 updates, 0 removals
Updates: symfony/symfony:v3.4.7, vich/uploader-bundle:1.8.2
  - Updating symfony/symfony (v3.3.16 => v3.4.7): Reading C:/Users/dmeigs.TLINENM/AppData/Local/Composer/files/symfony/symfony/857c1e0dee3406d607f3cd84dee2c6ecf877fb22.zip from cache
Loading from cache Extracting archive
    REASON: Required by the root package: Install command rule (install symfony/symfony v3.3.16|install symfony/symfony 3.3.x-dev|install symfony/symfony 3.4.x-dev|install symfony/symfony v3.4.0|install symfony/symfony v3.4.0-BETA1|install symfony/symfony v3.4.0-BETA2|install symfony/symfony v3.4.0-BETA3|install symfony/symfony v3.4.0-BETA4|install symfony/symfony v3.4.0-RC1|install symfony/symfony v3.4.0-RC2|install symfony/symfony v3.4.1|install symfony/symfony v3.4.2|install symfony/symfony v3.4.3|install symfony/symfony v3.4.4|install symfony/symfony v3.4.5|install symfony/symfony v3.4.6|install symfony/symfony v3.4.7|install symfony/serializer 3.3.x-dev|install symfony/serializer 3.4.x-dev|install symfony/serializer v3.3.0|install symfony/serializer v3.3.0-BETA1|install symfony/serializer v3.3.0-RC1|install symfony/serializer v3.3.1|install symfony/serializer v3.3.10|install symfony/serializer v3.3.11|install symfony/serializer v3.3.12|install symfony/serializer v3.3.13|install symfony/serializer v3.3.14|install symfony/serializer v3.3.15|install symfony/serializer v3.3.16|install symfony/serializer v3.3.2|install symfony/serializer v3.3.3|install symfony/serializer v3.3.4|install symfony/serializer v3.3.5|install symfony/serializer v3.3.6|install symfony/serializer v3.3.7|install symfony/serializer v3.3.8|install symfony/serializer v3.3.9|install symfony/serializer v3.4.0|install symfony/serializer v3.4.0-BETA1|install symfony/serializer v3.4.0-BETA2|install symfony/serializer v3.4.0-BETA3|install symfony/serializer v3.4.0-BETA4|install symfony/serializer v3.4.0-RC1|install symfony/serializer v3.4.0-RC2|install symfony/serializer v3.4.1|install symfony/serializer v3.4.2|install symfony/serializer v3.4.3|install symfony/serializer v3.4.4|install symfony/serializer v3.4.5|install symfony/serializer v3.4.6|install symfony/serializer v3.4.7)

  - Updating vich/uploader-bundle (1.7.1 => 1.8.2): Reading C:/Users/dmeigs.TLINENM/AppData/Local/Composer/files/vich/uploader-bundle/fa3d5fafebc3c184efe63f1f1ba1056fb7464ac0.zip from cache
Loading from cache Extracting archive
    REASON: Required by the root package: Install command rule (install vich/uploader-bundle 1.7.1|install vich/uploader-bundle 1.7.0|install vich/uploader-bundle 1.7.1|install vich/uploader-bundle 1.8.0|install vich/uploader-bundle 1.8.1|install vich/uploader-bundle 1.8.2|install vich/uploader-bundle 1.8.x-dev)

Reading C:\Users\dmeigs.TLINENM\Documents\websites\AYSOUnited/vendor/composer/installed.json
Reading ./composer.lock
Writing lock file
Generating autoload files
Reading ./composer.lock
ocramius/package-versions:  Generating version class...
> post-update-cmd: @symfony-scripts
ocramius/package-versions: ...done generating version class
> symfony-scripts: Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> symfony-scripts: Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> symfony-scripts: Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

In Container.php line 297:

  Circular reference detected for service "routing.loader", path: "routing.loader".

cache:clear [--no-warmup] [--no-optional-warmers] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception

  An error occurred when executing the ""cache:clear --no-warmup"" command:

  In Container.php line 297:

    Circular reference detected for service "routing.loader", path: "routing.loader".

  cache:clear [--no-warmup] [--no-optional-warmers] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--
  ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>

Exception trace:
 () at C:\Users\dmeigs.TLINENM\Documents\websites\AYSOUnited\vendor\sensio\distribution-bundle\Composer\ScriptHandler.php:293
 Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::executeCommand() at C:\Users\dmeigs.TLINENM\Documents\websites\AYSOUnited\vendor\sensio\distribution-bundle\Composer\ScriptHandler.php:143
 Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:282
 Composer\EventDispatcher\EventDispatcher->executeEventPhpScript() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:205
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:81
 Composer\EventDispatcher\EventDispatcher->dispatch() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:189
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:96
 Composer\EventDispatcher\EventDispatcher->dispatchScript() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Installer.php:322
 Composer\Installer->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Command/UpdateCommand.php:161
 Composer\Command\UpdateCommand->execute() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Command/Command.php:242
 Symfony\Component\Console\Command\Command->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Application.php:842
 Symfony\Component\Console\Application->doRunCommand() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Application.php:193
 Symfony\Component\Console\Application->doRun() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Console/Application.php:251
 Composer\Console\Application->doRun() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Console/Application.php:100
 Composer\Console\Application->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/bin/composer:58
 require() at C:\ProgramData\ComposerSetup\bin\composer.phar:24



OK, I see toy have this error on clear cache step.

First of all, I let's bump "symfony/swiftmailer-bundle" constraint to "^2.6.4", I see you have lower one. Also, let's use "symfony/symfony": "3.4.*" to allow only patch updates and try again. If you see the same error, let's temporarily remove this line:

So, the idea is to achieve green composer update operation. Then you can probably debug it later why cache clear thrown an error.

Btw, do you have any custom route loaders?


Dan_M Avatar


I found the problem!!!! I had two controllers responding to the same path (one in each of the two bundles I was developing). Evidently that creates a routing loop. For some reason, Symfony 3.3 was just fine with that, but Symfony 3.4 was throwing errors. It looked like a problem with the upgrade, but it was a problem in my code that I was not aware of.

So, life is good! Thanks for your help.


Hey Dan,

Ah, not an obvious problem :) Glad you found a problem!


Vladimir Z. Avatar
Vladimir Z. Avatar Vladimir Z. | posted 5 years ago

Going back to the REST tutorial, in case of JwtTokenAuthenticator what functionality would you put into supports supports() and how should getCredentials() be refactored?
Thank you!


Hey Vlad,

I think it may be refactored as:

class JwtTokenAuthenticator extends AbstractGuardAuthenticator
    public function supports(Request $request)
        return $request->headers->has('Authorization');

    public function getCredentials(Request $request)
        $extractor = new AuthorizationHeaderTokenExtractor(

        $token = $extractor->extract($request);
        if (!$token) {
            return null;

        return $token;


Vladimir Z. Avatar
Vladimir Z. Avatar Vladimir Z. | Victor | posted 5 years ago

Thanks, Victor!
There is only one minor detail. If you look at the PHPDoc for the getCredentials function in AuthenticatorInterface, it says the return value must be Any non-null value
What should it be, if the $token is null?


Hey Vlad,

Ah, then probably the best would be:

    public function getCredentials(Request $request)
        $extractor = new AuthorizationHeaderTokenExtractor(

        $token = $extractor->extract($request);

        return [
            'token' => $token,

Actually, the same example you can see in docs: https://symfony.com/doc/current/security/guard_authentication.html#step-1-create-the-authenticator-class


Vladimir Z. Avatar
Vladimir Z. Avatar Vladimir Z. | Victor | posted 5 years ago

Thank you!

Kribo Avatar

How does one get the color green in the command prompt ??
All I get is Black & White and I'm a bit jealous. Do I need to buy a Mac?

-1 Reply

Hey @kribo,

Haha, it depends :) Btw, what OS you are on? Somehow your terminal does not allow ansi output by default. Well, you can try to force ANSI output with --ansi flag, for example, Composer has this option, so try:

$ composer --ansi

Do you see color output now? The same for Symfony commands, i.e. bin/console, try to add --ansi flasg to force ANSI output. What terminal do you use? I think you can configure your terminal to always support ANSI output and you won't need to pass that flag.


Kribo Avatar

Got it to work..

OS = Win10 pro => had to install ANSICON from
1- https://github.com/adoxa/an....
2- open cmd and navigate to the unzipped folder
3- Navigate to x64 (if you have a 64 bit machine) otherwise navigate to x86
4- Type ansicon.exe -h and you will get the following:
D:\Data\ansicon\x86>ansicon.exe -h

And bingo it works I've now also got a green bar when I run the server....lol


Great! Thanks for sharing it with others :)


Default user avatar
Default user avatar Billias McPappas | Kribo | posted 5 years ago

If you are using Windows, check a tool called ConEmu. Besides colors and stuff, it allows multiple tabs in single console, and even search functionality.

Check it out, and thank me later :D


Hey Billias,

Hm, looks like a great tip, so I'll thank you now ;) Thanks for the help!


Default user avatar
Default user avatar Billias McPappas | Victor | posted 5 years ago


it truly is a nice tool for windows users. My current development stack is 1 Symfony website & one Symfony API. So i need two consoles for the dev servers, two more for executing console commands etc, and a fifth (!) for running my front-end (i am using webpack dev server). So after spending a lot of time changing between consoles, i found my peace with this one!

Thanks for KnpU though, it is also a life-saver when it comes to get a grasp on what is going on with new Symfony versions!


Hey Billias,

Yep, I totally understand you, we have Webpack dev-server too so I always have a few tabs for one project :)

And thanks for the kind words about KnpU screencasts, we're working hard on releasing new important updates as soon as we can.


Cat in space

"Houston: no signs of life"
Start the conversation!

What PHP libraries does this tutorial use?

// composer.json
    "require": {
        "php": "^7.1.3",
        "composer/package-versions-deprecated": "^1.11", // 1.11.99
        "doctrine/doctrine-bundle": "^1.6", // 1.8.1
        "doctrine/doctrine-cache-bundle": "^1.2", // 1.3.2
        "doctrine/doctrine-migrations-bundle": "^1.1", // v1.3.1
        "doctrine/orm": "^2.5", // v2.7.2
        "fzaninotto/faker": "^1.7", // v1.7.1
        "knplabs/knp-markdown-bundle": "^1.4", // 1.6.0
        "sensio/framework-extra-bundle": "^5.0", // v5.1.3
        "stof/doctrine-extensions-bundle": "dev-master", // dev-master
        "symfony/asset": "^4.0", // v4.0.1
        "symfony/console": "^4.0", // v4.0.1
        "symfony/flex": "^1.0", // v1.9.10
        "symfony/form": "^4.0", // v4.0.1
        "symfony/framework-bundle": "^4.0", // v4.0.1
        "symfony/lts": "^4@dev", // dev-master
        "symfony/maker-bundle": "^1.0", // v1.0.2
        "symfony/monolog-bundle": "^3.1", // v3.1.2
        "symfony/polyfill-apcu": "^1.0", // v1.6.0
        "symfony/profiler-pack": "^1.0", // v1.0.3
        "symfony/security-bundle": "^4.0", // v4.0.1
        "symfony/security-csrf": "^4.0",
        "symfony/swiftmailer-bundle": "^3.1", // v3.1.6
        "symfony/translation": "^4.0", // v4.0.1
        "symfony/twig-bundle": "^4.0", // v4.0.1
        "symfony/validator": "^4.0", // v4.0.1
        "symfony/web-server-bundle": "^4.0", // v4.0.1
        "symfony/yaml": "^4.0" // v4.0.1
    "require-dev": {
        "symfony/dotenv": "^4.0", // v4.0.1
        "symfony/phpunit-bridge": "^4.0", // v4.0.1
        "doctrine/doctrine-fixtures-bundle": "^3.0" // 3.0.2