New in Symfony 3.3: Deprecated the ClassLoader component

Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.

Contributed by
Nicolas Grekas
in #21353.

The ClassLoader component was released on April 2012, when Composer was just a few months old and developing PHP applications was pretty different than today. Class autoloading is the mechanism used by PHP to load the classes referenced by your code and which haven't been required or included yet.

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.

Although this component was useful to improve the application performance when using PHP 5, in the new PHP 7 era this is no longer true. That's why we've decided to deprecate the entire ClassLoader component.

If you use PHP 7, you can already test this change in your Symfony applications by removing the following line in your front controllers (both web/app.php and web/app_dev.php):

// app_dev.php
// ...
$kernel = new AppKernel('dev', true);
// $kernel->loadClassCache();   <-- comment/remove this line
// ...

// app.php
// ...
$kernel = new AppKernel('prod', false);
// $kernel->loadClassCache();   <-- comment/remove this line
// ...

You shouldn't notice any performance impact in your application, as long as you use PHP 7 and the class loader provided by Composer. Finally, you should read the class loading optimization article recently published by Composer to know more about the options that will make your application faster.

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.

New in Symfony 3.3: Deprecated the ClassLoader component

Tweet this


Should this be done for development environment also, because the composer link advises against that?
Note: You should not enable any of these optimizations in development as they all will cause various problems when adding/removing classes. The performance gains are not worth the trouble in a development setting.
@Don you are right: the idea is to remove the `loadClassCache()` from both "prod" and "dev" ... but enable the Composer optimizations only in the prod servers.
Great one!
Does this mean we also no longer need the "include_once __DIR__.'/../var/bootstrap.php.cache';" in our "app.php" front controllers?

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.