关于yii 的baseyii.php的autoload方法

WBOY
Release: 2016-06-23 13:23:56
Original
903 people have browsed it

 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?");        }    }
Copy after login

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


回复讨论(解决方案)

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

谢谢

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!