How to check if a class/object is loaded in php?
<p>I have this code:</p>

<pre><code>&lt;?php  
    define('ga_email', 'xxxxxxxxx@xxxxx.com');    // GA Email
    define('ga_password', 'xxxxxxxxxxx');         // 2-part authorization password
    define('profile_id', 'xxxxxxxxx');            // Analytics profile ID
    $gapi_url = 'gapi/gapi.class.php';
    require_once $gapi_url;
    $ga = new gapi(ga_email,ga_password);

    // here goes next code

?&gt;
</code></pre>

<p>and it's ok. Gapi will load.</p>

<p>However, if I change ga_password from xxxxxxxxxxx to yyyyyyyyyyy (so the information for logging into GA are incorrect) I get a nasty error, that gapi is not loaded etc.</p>

<p>I need some if condition to implement so it checks if my object $ga was created or not and execte a code only then. </p>

<p>e.g.:</p>

<pre><code> &lt;?php  
        define('ga_email', 'xxxxxxxxx@xxxxx.com');    // GA Email
        define('ga_password', 'yyyyyyyyyyyyyy');      // 2-part authorization password
        define('profile_id', 'xxxxxxxxx');            // Analytics profile ID
        $gapi_url = 'gapi/gapi.class.php';
        require_once $gapi_url;
        $ga = new gapi(ga_email,ga_password);

        if($ga  loaded) {
           // SUCCESS
           // here goes next code
        } else {
           // FAILURE
           echo "Your connection details are wrong.";
        }

 ?&gt;
</code></pre>

<p>So, instead a bad looking PHP error I will get a nicer "Your connection details are wrong."message.</p>
