Home >php教程 >php手册 >【伪】类自动加载

【伪】类自动加载

WBOY
WBOYOriginal
2016-06-06 19:34:511623browse

用于类自动加载 PPPHP /** * 加载类库 * 会优先加载项目目录lib中的类 * @param str $lib 类名称 * @param str $dir like /Core/lib/ * @return obj */protected function b($lib){$systempath = CORE.'/lib/'.$lib.'.class.php';$apppath = APP.'/lib/'.$lib

用于类自动加载 PPPHP
	/**
	 * 加载类库
	 * 会优先加载项目目录lib中的类
	 * @param str $lib 类名称
	 * @param str $dir like /Core/lib/
	 * @return obj
	 */
	protected function b($lib)
	{
		$systempath = CORE.'/lib/'.$lib.'.class.php';
		$apppath = APP.'/lib/'.$lib.'.class.php';
		//引入lib
		if(file_exists($apppath)) 
		{
			include_once $apppath;
		}
		else
		{
			if(file_exists($systempath))
			{
				include_once $systempath;
			}
			else 
			{
				show_error('库'.$lib.'不存在');
			}
		}
		$lib = new $lib();
		return $lib;//返回OBJ
	}
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
Previous article:xotpl框架Next article:是否为空函数改造