I have been using __autoload for a while now and it works fine but since they recommend not using it any more I think I need to move forward. Currently I load __autoload every time I enter the system as follows:
function __autoload($object){
$source = $_SERVER['DOCUMENT_ROOT'] . '/classes/' . str_replace('_', '/', $object) . '.php';
require_once($source);
}
A sample class would be named Admin_LogicIn and the filename would be LogicIn.php in the Admin subdirectory.
To instantiate it is just new Admin_LogicIn(arg1, arg2); and it works great!
Recently I wanted to use the Stripe library and they are structured differently with namespace and class with the same name all in one directory which would be a subdirectory on my system. So short of changing their files, which I obviously don’t want to do, I can’t instantiate their classes.
So first question, can I make the adjustment to
function my_autoload($object) {
$source = $_SERVER['DOCUMENT_ROOT'] . '/classes/' . str_replace('_', '/', $object) . '.php';
require_once($source);
}
spl_autoload_register('my_autoload');
Does that leave me in the same place I am now just using spl_autoload instead of __autoload? And if it does, can I ‘spl_autoload_register’ another function to cover the other library and how are namespaces handled in that case?
Thanks