title: Where's the difference between self and $this-> in a PHP class or PHP method?
body: <p>Where's the difference between <code>self</code> and <code>$this-&gt;</code> in a PHP class or PHP method?</p>
  
  <p>Example:</p>
  
  <p>I've seen this code recently. </p>
  
  <pre><code>public static function getInstance() {
  
      if (!self::$instance) {
          self::$instance = new PDO("mysql:host='localhost';dbname='animals'", 'username', 'password');;
          self::$instance-&gt; setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      }
      return self::$instance;
  }
  </code></pre>
  
  <p>But I remember that <code>$this-&gt;</code> refers to the current instance (object) of a class (might also be wrong). However, what's the difference?</p>