Home  >  Article  >  Backend Development  >  关于yii 的baseyii.php的autoload步骤

关于yii 的baseyii.php的autoload步骤

WBOY
WBOYOriginal
2016-06-13 12:26:33946browse

关于yii 的baseyii.php的autoload方法

<br /> public static function autoload($className)<br />    {<br />        if (isset(static::$classMap[$className])) {<br />            $classFile = static::$classMap[$className];<br />            if ($classFile[0] === '@') {<br />                $classFile = static::getAlias($classFile);<br />            }<br />        } elseif (strpos($className, '\\') !== false) {<br />            $classFile = static::getAlias('@' . str_replace('\\', '/', $className) . '.php', false);<br />            if ($classFile === false || !is_file($classFile)) {<br />                return;<br />            }<br />        } else {<br />            return;<br />        }<br /><br />        include($classFile);   //源码  include($classFile);<br /><br />        if (YII_DEBUG && !class_exists($className, false) && !interface_exists($className, false) && !trait_exists($className, false)) {<br />            throw new UnknownClassException("Unable to find '$className' in file: $classFile. Namespace missing?");<br />        }<br />    }<br />

$classFile =static::$classMap[$className]有在yii.php加载了映射表为什么后面用include而不用include_once
// yii.php代码下面的语句读取了一个映射表
Yii::$classMap = include(__DIR__ . '/classes.php');

------解决思路----------------------
因为前面的代码已经判断了是否已经include。所以这里不需要once.

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