我看到不同的库(在本例中为Symfony)phpunit bootstrap.php代码通常包括:
spl_autoload_register(function ($class) {
if (0 === strpos(ltrim($class, '/'), 'Symfony\Component\EventDispatcher')) {
if (file_exists($file = __DIR__.'/../'.substr(str_replace('\\', '/', $class), strlen('Symfony\Component\EventDispatcher')).'.php')) {
require_once $file;
}
}
});
我想知道在什么情况下这个班级名称会有一个前导斜杠?
答案 0 :(得分:1)
我不是Symfony的专家,但如果它有名称空间 Symfony \ Component \ EventDispatcher ,看起来他们正在使用文件名并尝试加载它。 ltrim()只会删除任何残留,以便在添加自己的搜索路径时不会发生错误。
我只能猜测,但我很确定这是正在发生的事情。