title: Lifetime of a static variable
body: <p>I'm going through a Joomla book, and I came across the following piece of code in the chapter of MVC pattern:</p>
  
  <pre><code>class QuizController extends JController
  {
      static function &amp;getInstance(/* some PHP code... */)
      {
          // use a static array to store controller instances
          static $instances;
  
          if (!$instances)
          {
              $instances = array();
          }
  
          /* some PHP code... */
  
          // return a reference to the controller
          return $instances[$class];
      }
  }
  </code></pre>
  
  <p>What is the lifetime of <code>$instances</code>? When is it destroyed?</p>
  
  <p>If it is alive during the lifetime of the request, then declaring <code>$instances</code> static doesn't make sense, because this code will be run once.<br>
  If it is alive during user session, how does PHP engine knows this?</p>