spl_autoload_register 是注册php auto_load的函数,这个函数可以多次加载
每一个函数应该都有返回值(boolean),如果返回值为true则认为已经加载成功就退出了加载过程,如果失败则继续调用后边的auto_load函数加载php文件,当然如果最后一个auto_load也没有加载成功这时候就没有加载完成,new的时候就会报错。
<?php
/**
* Created by PhpStorm.
* User: chengtao
* Date: 14-7-3
* Time: 上午11:27
*/
define('BASE_PATH',dirname(__FILE__).'/') ;
function cron_autoload1 ($name) {
$file = BASE_PATH.'lib1/'.$name.'.class.php';
if(file_exists($file)){
include_once($file);
return true;
}
}
function cron_autoload2 ($name) {
$file = BASE_PATH.'lib2/'.$name.'.class.php';
if(file_exists($file)){
include_once($file);
return true;
}
}
spl_autoload_register('cron_autoload1');
spl_autoload_register('cron_autoload2');
new Class1();
new Class2();