如何检查php中是否存在命名空间
发布时间:2020-12-13 13:43:04 所属栏目:PHP教程 来源:网络整理
导读:我有一个 PHP库 https://github.com/tedivm/Fetch,它使用Fetch命名空间,我想在我的脚本中检查它的存在. 我的脚本代码: // Load Fetchspl_autoload_register(function ($class) { $file = __DIR__ . '/vendor/' . strtr($class,'','/') . '.php'; if (file
|
我有一个
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 FetchServer($server,$port);
但始终显示此消息.但图书馆正在全力以赴. 在此先感谢您的帮助!
您需要在我认为的class_exists中使用整个命名空间.所以类似于:
class_exists('FetchServer')
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
