title: A new Instances of Singleton Class in PHP for each HTTP request
body: <p>I have the following Singleton Class in PHP.</p>
  
  <pre><code>class CounterBalance{
      private static $instance;
  
      private $counterBalance;
  
      private function __construct(){ 
          $this-&gt;counterBalance = mt_rand(1, 4);      
      }
  
      // Getter method for creating/returning the single instance of this class
      public final static function getInstance() {
          if(!self::$instance) {
              self::$instance = new CounterBalance();
              echo "CounterBalance constructed &lt;br/&gt;";
          }
          return self::$instance;
      }
  
      public function getCounterBalanceValue() {
          return $this-&gt;counterBalance;
      }
  
  }
  </code></pre>
  
  <p>But in the class when I do something like </p>
  
  <pre><code>CounterBalance::getInstance()-&gt;getCounterBalanceValue();
  </code></pre>
  
  <p>on the same php page, it works properly. But it not working properly across pages. I get more than one instance of CounterBalance, when I do the same function call in the subsequent php page.</p>
  
  <p>Can anyone one please explain why this happens. </p>
  
  <p>Thanks in advance.</p>