Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jeroenvanrensen's avatar

Does PHP load classes with autoloading?

Hi everyone,

Just a small question about PHP.

I found this piece of code on the official PHP Documentation:

spl_autoload_register(function ($class_name) {
    include $class_name . '.php';
});

And I was wondering: does this really import/load all the classes. Or do you have to call use before PHP actually is going to import it?

Because if it does, I guess it would make it really slow.

I would like to hear your answers!

Thank you! Jeroen

0 likes
2 replies
automica's avatar

@jeroenvanrensen when you install a package using composer, it generates an class map and list files list and saves it within the /vendor/composer/ directory.

you'll see a whole load of files prefixed with autoload_*

That means you don't need to autoload every time you hit the app, as laravel uses the cached file list.

This lesson goes over the basics of how composer autoloads:

https://laracasts.com/series/php-for-beginners/episodes/21

jlrdw's avatar

But you still need your use statement. That and autoload is two different things.

Please or to participate in this conversation.