I built an auto load method that essentially is as follows:
public function load_class($class){
$path = str_replace('_', '/', $class);
if(file_exists(get_template_directory() . '/' . $path . '.php')){
require_once(get_template_directory() . '/' . $path . '.php');
}
}
One of the things I would like to do is say:
if this class has already been required then just call it instead of having to do a require_once() for every time the class is called, extended or instantiated.
How ever I am not sure how to do this….Thats where I am asking for help or does the require_once essentially “cache” the class once it has been required? My understanding is that it only requires it once per call. that is every call it must require it again….???
If you are using that as an autoloader, it will only run when the class isn’t defined in the first place.
In addition to this,
require_once()keeps track of the file that was loaded. If you callrequire_once()again on the same file, nothing will happen.