我有一个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);
但此消息始终显示。但图书馆正在全面运作。
预先感谢您的帮助!
最佳答案
我相信您需要使用 class_exists
中的整个命名空间。所以类似:
class_exists('Fetch\\Server')
关于php - 如何检查php中命名空间是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18337650/