小编Max*_*huk的帖子

如何检查php中是否存在命名空间

我有一个PHP库 https://github.com/tedivm/Fetch,它使用Fetch命名空间,我想在我的脚本中检查它的存在.

我的脚本代码:

// Load Fetch
spl_autoload_register(function ($class) {
    $file = __DIR__ . '/vendor/' . strtr($class, '\\', '/') . '.php';
    if (file_exists($file)) {
        require $file;

        return true;
    }
});

if (!class_exists('\\Fetch')) {
  exit('Failed to load the library: Fetch');
}
$mail = new \Fetch\Server($server, $port);
Run Code Online (Sandbox Code Playgroud)

但始终显示此消息.但图书馆正在全力以赴.

在此先感谢您的帮助!

php namespaces class exists

13
推荐指数
2
解决办法
2万
查看次数

标签 统计

class ×1

exists ×1

namespaces ×1

php ×1