I am reviving some old code that hasn't been used for some time and see that there is a depreciated function which, when I saw it, I thought was a custom function so was surprised that it could be depreciated but I came to realize that the underscores have some meaning. It was __autoload() and I did not write this code (a former colleague did) but I was able to fix the issue by reviewing a posting found elsewhere on this site so my question is mainly for the information.
My question is, what are the underscores for and what does this function actually do? It appears to load any function it finds in a file folder but this seems an odd thing to do. What could be the purpose?
This is the original giving the error
function __autoload($class){
$class = strtolower($class);
$fName = jBASE . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . $class .'.php';
$classFName = jBASE . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'class.'. $class .'.php';
if(file_exists($fName)):
require_once $fName;
elseif(file_exists($classFName)):
require_once($classFName);
endif;
}
and this is the version after I repaired it which gives no error
spl_autoload_register(function($class){
$class = strtolower($class);
$fName = jBASE . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . $class .'.php';
$classFName = jBASE . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'class.'. $class .'.php';
if(file_exists($fName)):
require_once $fName;
elseif(file_exists($classFName)):
require_once($classFName);
endif;
});