public static function autoload($className) { if (isset(static::$classMap[$className])) { $classFile = static::$classMap[$className]; if ($classFile[0] === '@') { $classFile = static::getAlias($classFile); } } elseif (strpos($className, '\\') !== false) { $classFile = static::getAlias('@' . str_replace('\\', '/', $className) . '.php', false); if ($classFile === false || !is_file($classFile)) { return; } } else { return; } include($classFile); //源码 include($classFile); if (YII_DEBUG && !class_exists($className, false) && !interface_exists($className, false) && !trait_exists($className, false)) { throw new UnknownClassException("Unable to find '$className' in file: $classFile. Namespace missing?"); } }
$classFile =static::$classMap[$className]有在yii.php加载了映射表为什么后面用include而不用include_once
// yii.php代码下面的语句读取了一个映射表
Yii::$classMap = include(__DIR__ . '/classes.php');
回复讨论(解决方案)
因为前面的代码已经判断了是否已经include。所以这里不需要once.
谢谢