本例尝试分别从 MyClass1.php
和 MyClass2.php
文件中加载
MyClass1
和
MyClass2
类。
<?php
//第一种
function
__autoload
(
$class_name
) {
require_once
$class_name
.
'.php'
;
}
$obj
= new
MyClass1
();
$obj2
= new
MyClass2
();
//第二种
if(!function_exists('__AutoINCLUDE'))
{
function __AutoINCLUDE($classname)
{
global $ROOT_PATH;
$filename = $ROOT_PATH.'/include/'.$classname. '.php';
if(file_exists($filename))
return require_once($filename);
}
}
spl_autoload_register('__AutoINCLUDE');
if(!function_exists('__AutoLoadDAO'))
{
function __AutoLoadDAO($classname)
{
global $ROOT_PATH;
$filename = $ROOT_PATH.'/include/DAO/'.$classname. '.php';
if(file_exists($filename))
return require_once($filename);
}
}
spl_autoload_register('__AutoLoadDAO');
{
function __AutoINCLUDE($classname)
{
global $ROOT_PATH;
$filename = $ROOT_PATH.'/include/'.$classname. '.php';
if(file_exists($filename))
return require_once($filename);
}
}
spl_autoload_register('__AutoINCLUDE');
if(!function_exists('__AutoLoadDAO'))
{
function __AutoLoadDAO($classname)
{
global $ROOT_PATH;
$filename = $ROOT_PATH.'/include/DAO/'.$classname. '.php';
if(file_exists($filename))
return require_once($filename);
}
}
spl_autoload_register('__AutoLoadDAO');
?>