I have a php library https://github.com/tedivm/Fetch and it uses Fetch namespace and I would like to check its existence in my script.
My script code:
// 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);
but this message is always displayed. But the library is fully working.
Thanks in advance for any help!
You need to use the entire namespace in the class_exists
I believe. So something like:
class_exists('Fetch\\Server')