note 84233 deleted from language.oop5.autoload by crell
| From: | crell@php.net | Date: | Mon, 04 Apr 2022 16:13:55 +0000 |
| Subject: | note 84233 deleted from language.oop5.autoload by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218036@lists.php.net to get a copy of this message | ||
Note Submitter: chris (at) xeneco (dot) co (dot) uk
----
I'm very taken with the autoload function, and thought I would share with you my implementation
of it:
<?php
function __autoload($class_name) {
//my settings class is a singleton instance that has parsed an ini file containing the locations of
all classes
$settings = Settings::Load();
$classes = $settings->getSettings('classes');
$path = $classes[$class_name];
if(file_exists($path)) {
require_once($path);
return true;
} else {
clearstatcache();
$classes = $settings->ReLoadSettings();
$path = $classes['classes'][$class_name];
}
if(file_exists($path)) {
require_once($path);
return true;
} else {
die("The requested library,".$class_name.", could not be found at
".$classes[$class_name][$i].". Please check your ini file");
}
}
?>