title: Fatal Error: Call to a member function addSnippet() on a non-object
body: <p>I'm making a little PHP function that will show the avatar of all the administrators in my database. For some reason, I get the following error when I try to call the function <code>$backend-&gt;addSnippet('login: show-admins');</code>. Here is the PHP Class.</p>
  
  <pre><code>&lt;?php
  
  class zBackend {
  
  private $adminCount;
  
  final public function fetchAdminInfo() {
      global $zip, $db, $tpl;
  
      $query = $db-&gt;prepare('SELECT first_name, last_name FROM zip__admins');
      $query-&gt;execute();
  
      $result = $query-&gt;fetchAll();
  
      $id = 1;
      foreach($result as $row) {
          $tpl-&gt;define('admin: first_name-' . $id, $row['first_name']);
          $tpl-&gt;define('admin: last_name-' . $id, $row['last_name']);
          $id++;
      }
      $this-&gt;adminCount = $id;
  }
  
  final public function addSnippet($z) {
      global $tpl;
  
      if(isset($z) &amp;&amp; !empty($z)) {
          $this-&gt;fetchAdminInfo();
  
          switch($z) {
              case 'login: show-admins':
                  $tpl-&gt;write('&lt;ul id="users"&gt;');
  
                  $id = 0;
                  while($this-&gt;adminCount &gt; $id) {
                      $tpl-&gt;write('&lt;li data-name="{admin: first_name-' . $id + 1 . '} {admin: last_name-' . $id + 1 . '}"&gt;');
                      $tpl-&gt;write('&lt;div class="av-overlay"&gt;&lt;/div&gt;&lt;img src="{site: backend}/img/avatars/nick.jpg" class="av"&gt;');
                      $tpl-&gt;write('&lt;span class="av-tooltip"&gt;{admin: first_name-' . $id + 1 . '} {admin: last_name-' . $id + 1 . '}&lt;/span&gt;');
                      $tpl-&gt;write('&lt;/li&gt;');
                  }
  
              break;
          }
      } else {
          return false;
      }
  }
  }
  ?&gt;
  </code></pre>
  
  <p>Here is where I set the function:</p>
  
  <pre><code>final public function __construct() {
      global $zip, $core, $backend;
  
      $this-&gt;Define('site: title', $zip['Site']['Title']);
      $this-&gt;Define('site: location', $zip['Site']['Location']);
      $this-&gt;Define('site: style', $zip['Site']['Location'] . '/_zip/_templates/_frontend/' . $zip['Template']['Frontend']);
      $this-&gt;Define('site: backend', $zip['Site']['Location'] . '/_zip/_templates/_backend/' . $zip['Template']['Backend']);
  
  
      $this-&gt;Define('social: email', $zip['Social']['Email']);
      $this-&gt;Define('social: twitter', $zip['Social']['Twitter']);
      $this-&gt;Define('social: youtube', $zip['Social']['Youtube']);
      $this-&gt;Define('social: facebook', $zip['Social']['Facebook']);
  
      $this-&gt;Define('snippet: show-admins', $backend-&gt;addSnippet('login: show-admins'));
  }
  </code></pre>
  
  <p>And here is where I call the function:</p>
  
  <pre><code>&lt;ul id="users"&gt;
    {snippet: show-admins}
    &lt;br class="clear"&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Here is where I declare $backend</p>
  
  <pre><code>&lt;?php
  session_start();
  
  error_reporting(E_ALL);
  ini_set('display_errors', '1');
  
  define('D', DIRECTORY_SEPARATOR);
  define('Z', '_zip' . D);
  define('L', '_lib' . D);
  define('C', '_class'. D);
  
  require Z . 'config.php';
  require Z . L . 'common.php';
  
  try {
  $db = new PDO($zip['Database']['Data']['Source']['Name'], $zip['Database']['Username'], $zip['Database']['Password']);
  } catch(PDOException $e) {
  die(zipError('ZipDB: Connection Failed', $e-&gt;getMessage()));
  }
  
  require Z . C . 'class.ztpl.php';
  require Z . C . 'class.zcore.php';
  require Z . C . 'class.zbackend.php';
  require Z . C . 'class.zmail.php';
  
  $tpl = new zTpl();
  $backend = new zBackend();
  $core = new zCore();
  ?&gt;
  </code></pre>
  
  <p>It works just fine if I put the code into the file, but that limits what I can do. I want to be able to do it in a class and use functions to call it. Any ideas?</p>