title: Why people use singletons in their PHP framework
body: <p>Ok guys I am struggling to understand why there is a need of singleton.</p>
  
  <p>Let's make a real example: I have a framework for a my CMS<br>
  I need to have a class that logs some information (let's stick on PHP).</p>
  
  <p>Example:</p>
  
  <pre><code>class Logger{
     private $logs = array();
  
     public function add($log) {
        $this-&gt;logs[]=$log;
     }      
  }
  </code></pre>
  
  <p>Now of course this <em>helper</em> object must be unique for the entry life of a page request of my CMS.<br>
  And to solve this we would make it a singleton (declaring private the constructor etc.)</p>
  
  <p>But Why in the hell a class like that isn't entirerly static? This would solve the need of the singleton pattern (that's considered bad pratice) Example:</p>
  
  <pre><code>class Logger {
      private static $logs = array();
  
      public static function add($log) {
          self::$logs[]=$log;
      }
  }
  </code></pre>
  
  <p>By making this helper entirely static, when we need to add a log somewhere in our application we just need to call it statically like: <code>Logger::add('log 1');</code> vs a singleton call like: <code>Logger::getInstance()-&gt;add('log 1');</code></p>
  
  <p>Hope someone makes it easy to understand for me why <strong>use singleton over static class</strong> in PHP.</p>
  
  <h2>Edit</h2>
  
  <p><a href="http://moisadoru.wordpress.com/2010/03/02/static-call-versus-singleton-call-in-php/" rel="nofollow">This is a pretty</a> nice lecture on the singleton vs static class for who is interested, thanks to @James. (Note it doesn't address my question) </p>