我使用CI框架,下面的代码是一个生成器,旨在生成类公共方法列表:
$directory = FCPATH.APPPATH.'controllers/';
$exclude = array('shell');
$filter = function ($file, $key, $iterator) use ($exclude) {
if ($iterator->hasChildren() && !in_array($file->getFilename(), $exclude)) {
return true;
}
return $file->isFile();
};
$innerIterator = new RecursiveDirectoryIterator(
$directory,
RecursiveDirectoryIterator::SKIP_DOTS
);
$iterator = new RecursiveIteratorIterator(
new RecursiveCallbackFilterIterator($innerIterator, $filter)
);
foreach ($iterator as $pathname => $fileinfo) {
if (!preg_match("/\.(php)*$/i", $pathname, $matches)) {
continue;
}
$last = strrpos($pathname, '/');
$second_last = strrpos($pathname, '/', $last - strlen($pathname) - 1);
$last_folder_name = substr($pathname, $second_last + 1, $last - $second_last - 1);
if($last_folder_name == 'controllers')
{
continue;
}
require_once $pathname;
$module_name = & $last_folder_name;
$controller_name = ucfirst($fileinfo->getBasename('.php'));
$reflection_class = new ReflectionClass($controller_name);
}
我使用此代码取消设置变量:
unset($pathname);
unset($controller_name);
unset($reflection_class);
continue;
我似乎取消了对象,但它仍然说:
Fatal error: Cannot redeclare class Index in ...