Debugging Symfony components

Warning: This blogpost has been posted over two years ago. That is a long time in development-world! The story here may not be relevant, complete or secure. Code might not be complete or obsoleted, and even my current vision might have (completely) changed on the subject. So please do read further, but use it with caution.
Posted on 31 Dec 2014
Tagged with: [ cache ]  [ symfony ]  [ xdebug

Don’t you hate it when you are stepping through your debugger during a Symfony application debug session, and all of a sudden it cannot find files anymore as Symfony uses code located in the bootstrap.php.cache instead of the actual Symfony component. Symfony creates these cache-classes in order to speed up execution, but it makes that xdebug cannot find the correct code to step through anymore.

It’s probably posted many times already, but I couldn’t find it so I’m adding it to my blogpost as well, but it’s an easy fix. In your app_dev.php, change the following:

// CHANGE: Change from bootstrap.php.cache to autoload.php
$loader = require_once __DIR__.'/../app/autoload.php';

require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('dev', true);
// CHANGE: Comment the next line to disable cache loading
$request = Request::createFromGlobals();

From this point on, Symfony will use the original code which you can easily step through.