Symfony
sponsored by SensioLabs
Menu
  • About
  • Documentation
  • Screencasts
  • Cloud
  • Certification
  • Community
  • Businesses
  • News
  • Download
  1. Home
  2. Documentation
  3. Components
  4. The ClassLoader Component
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud
Search by Algolia

Table of Contents

  • Usage
  • Installation
  • Learn More

The ClassLoader Component

Edit this page

Warning: You are browsing the documentation for Symfony 3.1, which is no longer maintained.

Read the updated version of this page for Symfony 6.2 (the current stable version).

The ClassLoader Component

The ClassLoader component provides tools to autoload your classes and cache their locations for performance.

Caution

The ClassLoader component was deprecated in Symfony 3.3 and it will be removed in 4.0. As an alternative, use Composer's class loading mechanism.

Usage

Whenever you reference a class that has not been required or included yet, PHP uses the autoloading mechanism to delegate the loading of a file defining the class. Symfony provides three autoloaders, which are able to load your classes:

  • The PSR-0 Class Loader: loads classes that follow the PSR-0 class naming standard;
  • The PSR-4 Class Loader: loads classes that follow the PSR-4 class naming standard;
  • MapClassLoader: loads classes using a static map from class name to file path.

Additionally, the Symfony ClassLoader component ships with a wrapper class which makes it possible to cache the results of a class loader.

When using the Debug component, you can also use a special DebugClassLoader that eases debugging by throwing more helpful exceptions when a class could not be found by a class loader.

Installation

You can install the component in 2 different ways:

  • Install it via Composer (symfony/class-loader on Packagist);
  • Use the official Git repository (https://github.com/symfony/class-loader).

Then, require the vendor/autoload.php file to enable the autoloading mechanism provided by Composer. Otherwise, your application won't be able to find the classes of this Symfony component.

Learn More

  • The PSR-0 Class Loader
  • Cache a Class Loader
  • The PSR-0 Class Loader
  • The Class Map Generator
  • Debugging a Class Loader
  • MapClassLoader
  • The PSR-4 Class Loader
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
We stand with Ukraine.
Version:
Become certified from home

Become certified from home

Check Code Performance in Dev, Test, Staging & Production

Check Code Performance in Dev, Test, Staging & Production

↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

Avatar of Arnaud Frézet, a Symfony contributor

Thanks Arnaud Frézet for being a Symfony contributor

2 commits • 89 lines changed

View all contributors that help us make Symfony

Become a Symfony contributor

Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

Learn how to contribute

Symfony™ is a trademark of Symfony SAS. All rights reserved.

  • What is Symfony?
    • Symfony at a Glance
    • Symfony Components
    • Case Studies
    • Symfony Releases
    • Security Policy
    • Logo & Screenshots
    • Trademark & Licenses
    • symfony1 Legacy
  • Learn Symfony
    • Symfony Docs
    • Symfony Book
    • Reference
    • Bundles
    • Best Practices
    • Training
    • eLearning Platform
    • Certification
  • Screencasts
    • Learn Symfony
    • Learn PHP
    • Learn JavaScript
    • Learn Drupal
    • Learn RESTful APIs
  • Community
    • SymfonyConnect
    • Support
    • How to be Involved
    • Code of Conduct
    • Events & Meetups
    • Projects using Symfony
    • Downloads Stats
    • Contributors
    • Backers
  • Blog
    • Events & Meetups
    • A week of symfony
    • Case studies
    • Cloud
    • Community
    • Conferences
    • Diversity
    • Documentation
    • Living on the edge
    • Releases
    • Security Advisories
    • SymfonyInsight
    • Twig
    • SensioLabs
  • Services
    • SensioLabs services
    • Train developers
    • Manage your project quality
    • Improve your project performance
    • Host Symfony projects
    Deployed on
Follow Symfony
Search by Algolia