title: Test if a function is run from a static context
body: <p>I am writing a PHP class and have included a couple static functions for quick access as they are common for use and are simple in function. However they do use an object in them for database access. I will likely be using these static methods from both a static and non-static context throughout my code so I want to be able to test whether the function was called from a static or non-static context so that I can avoid creating a duplicate object if the function was called from a non-static context (this instance object and the one within the function to be used statically). Is there any way that I can test this in the function so that I can use the instance object if the function is called from a non-static context and create it's own object if the function is called from a static context?</p>
  
  <p>Code Example:</p>
  
  <pre><code>class MyClass {
    private $db;
  
    function __constuct(){
      $this-&gt;db = new DBConnect();
    }
  
    public static function myFunction(){
      if(/* Is static */){
        $db = new DBConnect();
      } else {
        $db =&amp; $this-&gt;db;
      }
      // Do processing with $db, etc.
    }
  }
  </code></pre>