This is a minimalistic, Drupal 8 compatible autoloader for PSR-4.


  • Support for PSR-4 in all enabled modules and profiles.
  • Minimal module size. Ever had to find out why the hell your class is not autoloading? With psr0 you'll find out. It's ~80 lines of code, including comments.
  • Early bootstrap. Autoloading works even in hook_install() and hook_boot().
  • Also works during test-runs.


Simply add a dependency on this module if you want to use autoloading in your module. Use PSR-4 namespaces and you're good to go. No further configuration needed.

Examples for classes and paths

Drupal\your_module\YourClass -> …/your_module/src/YourClass.php
Drupal\your_module\SomeInterface -> …/your_module/src/SomeInterface.php
Drupal\your_module\SubNamespace\Class -> …/your_module/src/SubNamespace/Class.php
Drupal\your_module\Tests\SomeTest -> …/your_module/src/Tests/SomeTest.php (since 1.4)
Drupal\your_module\Tests\SomeTest -> …/your_module/tests/src/SomeTest.php (since 1.4)

The same works also for profiles:

Drupal\your_profile\YourClass -> profiles/your_profile/src/YourClass.php
Drupal\your_profile\SomeInterface -> profiles/your_profile/src/SomeInterface.php
Drupal\your_profile\SubNamespace\Class -> profiles/your_profile/src/SubNamespace/Class.php
Drupal\your_profile\Tests\SomeTest -> profies/your_profile/src/Tests/SomeTest.php (since 1.4)
Drupal\your_profile\Tests\SomeTest -> profiles/your_profile/tests/src/SomeTest.php (since 1.4)

The lib/-prefix is still supported in 7.x-1.x although src/ was chosen as prefix for PSR-4 in D8.

Related modules / alternatives

  • X Autoload: Implements advanced caching, registration of custom prefixes, …
  • Classloader is a direct backport of the D8 autoloader.

None of these modules allows reliable autoloading during hook_install() - at least without further configuration. Both have a bigger footprint though in some cases their caching mechanisms may make them perform better.


The module is feature complete. No additional changes are planned.

Project information