Una implementazione che ho trovato su
konstrukt
Codice PHP:function search_include_path($filename) {
if (is_file($filename)) {
return $filename;
}
foreach (explode(PATH_SEPARATOR, ini_get("include_path")) as $path) {
if (strlen($path) > 0 && $path{strlen($path)-1} != DIRECTORY_SEPARATOR) {
$path .= DIRECTORY_SEPARATOR;
}
$f = realpath($path.$filename);
if ($f && is_file($f)) {
return $f;
}
}
return FALSE;
}
Codice PHP:function k_autoload($class_name) {
$filename = str_replace('_', '/', strtolower($class_name)).'.php';
if (search_include_path($filename)) {
require_once($filename);
}
}
spl_autoload_register('k_autoload');
![]()


Rispondi quotando