If I fail to include
a file in PHP, it reports.
But how do I know I successfully import GuzzleHttp\Cookie\CookieJar
Class ?
And how do I know it is a valid Class ?
namespace GuzzleHttp;
use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Promise;
If I fail to include
a file in PHP, it reports.
But how do I know I successfully import GuzzleHttp\Cookie\CookieJar
Class ?
And how do I know it is a valid Class ?
namespace GuzzleHttp;
use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Promise;
It is important to note that the use
statement will NOT include that class, therefore it would be impossible to detect if this (statement) was succesful.
However if you would try to instantiate one of the imported classes and the import would have failed, you'd get an error.
You usually use an autoloader for this, such as composer, but you can also write one yourself. More information about this at this page: What is Autoloading; How do you use spl_autoload, __autoload and spl_autoload_register?
Nowadays most application use autoload feature from composer.
You can check if a class exist via code:
if (!class_exists(CookieJar::class)) {
throw new Exception('class not found');
}
but class_exists
probably more useful when you do dynamic stuff.