title: PHP Fatal error: Using $this when not in object context
body: <p>I've got a problem:</p>
  
  <p>I'm writing a new WebApp without a Framework.</p>
  
  <p>In my <strong>index.php</strong> I'm using: <code>require_once('load.php');</code></p>
  
  <p>And in <strong>load.php</strong> I'm using <code>require_once('class.php');</code> to load my <strong>class.php</strong>.</p>
  
  <p>In my <strong>class.php</strong> I've got this error:</p>
  
  <blockquote>
    <p>Fatal error: Using $this when not in object context in class.php on line ... (in this example it would be 11)</p>
  </blockquote>
  
  <p>An example how my <em>class.php</em> is written:</p>
  
  <pre><code>class foobar {
  
      public $foo;
  
      public function __construct() {
          global $foo;
  
          $this-&gt;foo = $foo;
      }
  
      public function foobarfunc() {
          return $this-&gt;foo();
      }
  
      public function foo() {
          return $this-&gt;foo;
      }
  }
  </code></pre>
  
  <p>In my <em>index.php</em> I'm loading maybe <code>foobarfunc()</code> like this:</p>
  
  <pre><code>foobar::foobarfunc();
  </code></pre>
  
  <p>but can also be</p>
  
  <pre><code>$foobar = new foobar;
  $foobar-&gt;foobarfunc();
  </code></pre>
  
  <p>Why is the error coming?</p>