When exactly is the autoloader called? When exactly is the autoloader called? php php

When exactly is the autoloader called?


Under what circumstances/function calls are autoloaders called?

I realize that this has ended up basically being a secondary question given the problems noted in the comments, but it's still worth answering.

Autoload functions, that being a __autoload() function in your code or callbacks registered through spl_autoload_register, are called when -- and only when -- PHP needs to access a class that has not been defined. This is done everywhere with few exceptions, such as class_exists, which have arguments that tell PHP not to call any autoloaders.

The PHP manual has a page dedicated to autoloading. I recommend reviewing it if there's any confusion.


You can use debug_backtrace or debug_print_backtrace to find out where exactly the auto-loader function is being called.

Technically it should only be called by PHP when a script references a class name that does not exist.