__autoload() is no longer supported, use spl_autoload_register() instead

Description

The initial autoloader was a custom function, that was called whenever a class, interface or trait had to be loaded, but could not be found by PHP yet.

This approach was useful, but limited management operation: in particular, it was not possible to add more functions, or remove some of them. So, it was replaced with the spl_autoload_register() function, which add a closure to a list of autoloaders.

Example

<?php

function __autoload() {}

?>

Solutions

  • Give another name to the __autoload function, and register it as autoloader with spl_autoload_register().

  • Remove the __autoload function.

In previous PHP versions, this error message used to be __autoload()-is-deprecated,-use-spl_autoload_register()-instead.