我不是PHP专家;我正在尝试使用此TextRank Library来帮助项目。 我似乎遇到了一个奇怪的问题:即使添加了自动加载功能,在命令行上执行仍然会导致“找不到类”错误。所以这是布局:
调用其他类的代码(“主”代码):
echo realpath (__DIR__);
function __autoload($class_name) {
if(file_exists(__DIR__ . "/lib/TextRank/" . $class_name . '.php')) {
require_once(__DIR__ . "/lib/TextRank/" . $class_name . '.php');
} else {
throw new Exception("Unable to load $class_name.");
}
}
$config = new Config;
$textrank = new TextRank($config);
$keywords = $textrank->getKeywords("The only asynchronous, one-on-four game in Nintendo’s booth came from the “Wait, they’re still making that?” franchise that is Mario Party, and its buried presence didn’t bode well. Thankfully, Mario Party 10’s demo didn’t waste time with the series’ slowest crawl-around-a-board-game moments, instead jumping straight into four mini-games.");
var_dump($keywords);
这是我的目录结构:
然而,我仍然得到:
Fatal error: Class 'Config' not found in /path/to/test.php
这意味着:
这是否与类中使用的命名空间约定有关,例如:
(在/lib/TextRank/Config.php中)
namespace crodas\TextRank;
class Config
{
....
答案 0 :(得分:0)
是的。你需要做
$config = new crodas\TextRank\Config();
但是这不会被您的自动加载器捕获。您需要寻找兼容PSR-0的自动加载器。