title: PHP Singleton: not holding instance
body: <p>I'm just becoming dive into php after ages working in vb.net.</p>
  
  <p>I wanna write a logger class that runs as singleon over my webapp, here the code:</p>
  
  <pre><code>class cLog{
  
  private $data = NULL;
  
  
  static private $instance = NULL;
  
  static public function getInstance(){
      if(self::$instance == NULL){
          echo "empty!";
          self::$instance = new cLog();           
      }   
      return self::$instance;
  }
  
  
  private function __construct(){     
  }   
  private function __clone(){     
  }
  
  
  
  public function getData(){
      return self::getInstance()-&gt;data;
  }
  
  public function trace($o){
      self::getInstance()-&gt;data[] = $o;
  }
  
  }
  </code></pre>
  
  <p>What I expect is that, as i switch between pages of my application that make several calls to the cLog::trace() method, the data array increases and it's filled with all traces. But what I get is: everytime i run a page, the $instance is null so the object restarts (as you can see, I put an echo "empty!" line in the instance getter: it shows everytime)</p>
  
  <p>I guess there's something I'm misunderstanding in the php application-lifecycle....</p>
  
  <p>Here there's an usage example:</p>
  
  <pre><code>cLog::getInstance()-&gt;trace("hello world");
  $logs = cLog::getInstance()-&gt;getData();
  </code></pre>
  
  <p>Thanks</p>