According to http://php.net/manual/en/language.oop5.autoload.php the magic function __autoload()
will become DEPRECATED and DELETED (!) in upcoming PHP versions. The official alternative is spl_autoload()
. See http://www.php.net/manual/en/function.spl-autoload.php. But the PHP manual does not explain the proper use of this baby.
My question: How to replace this (my automatic class autoloader) with a version with spl_autoload()
?
function __autoload($class) {
include 'classes/' . $class . '.class.php';
}
Problem: I cannot figure out how to give that function a path (it only accepts namespaces).
By the way, there are a lot of threads regarding this topic here on SO, but none gives a clean & simple solution that replaces my sexy one-liner.
See Question&Answers more detail:os