Home >Backend Development >PHP Tutorial >哪位高手能帮小弟我解释一下自动加载类

哪位高手能帮小弟我解释一下自动加载类

WBOY
WBOYOriginal
2016-06-13 11:52:22847browse

谁能帮我解释一下自动加载类

/*
require(ROOT.'include/db.class.php');
require(ROOT.'include/conf.class.php');
require(ROOT.'include/log.class.php');
require(ROOT.'include/mysql.class.php');
require(ROOT.'Model/Model.class.php');
require(ROOT.'Model/TestModel.class.php');
*/


 function __autoload($class){
if(strtolower(substr($class,-5)) =='model'){
require(ROOT . 'Model/'.$class.'.class.php');
}else{
require(ROOT.'include/'.$class.'.class.php');
}
}
上面注销的是手动加载类,下面的是自动加载

我不太明白这个$class 是从哪出来的值
------解决方案--------------------
当你 new classname 时
如果这个 classname 类不存在,php 就会 调用 __autoload 函数,并将 classname 传过去
------解决方案--------------------
$class 就是找不到的类名
自动加载类就是自动加载找不到的类

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn