static $funcs = array();
... ...
$key = md5($path);
if (isset($funcs[$key])) return true;
if (file_exists(PC_PATH.$path)) {
include PC_PATH.$path;
} else {
$funcs[$key] = false;
return false;
}
$funcs[$key] = true;
return true;
上述代码是对include_once的优化,在每次include $file的时候都将$file放入$funcs中,避免重复导入。
那么问题是:$key = md5($path);
是什么依据,感觉这么做没什么意义。
首先我觉得这么做是没意义的,不会比直接用 include_once 更好。
然后这是一个比较常见的设计(虽然我觉得在这里没有什么意义),在需要通过 key 来查找 value 时,如果没有获取 key 的需要,那么可以将 key 散列之后作为 key, 这样可以: