title: PHP static function self:: in joomla JFactory class explanation?
body: <p>Hi I'm looking at the code of Joomla and trying to figure out what exactly happends in this function.</p>
  
  <p>index.php makes a call to function</p>
  
  <pre><code>$app = JFactory::getApplication('site');
  </code></pre>
  
  <p>jfactory.php code</p>
  
  <pre><code>public static function getApplication($id = null, $config = array(), $prefix='J')
  {
      if (!self::$application) {
  
          jimport('joomla.application.application');
  
          self::$application = JApplication::getInstance($id, $config, $prefix);
      }
  
      return self::$application;
  }
  </code></pre>
  
  <p>application.php code..</p>
  
  <pre><code>public static function getInstance($client, $config = array(), $prefix = 'J')
  {
      static $instances;
  
      if (!isset($instances)) {
          $instances = array();
      }
  
      ....... more code ........
  
      return $instances[$client];
  }
  </code></pre>
  
  <p>Now I cannot figure out in function getApplication why is self:$application used.</p>
  
  <pre><code>self::$application = JApplication::getInstance($id, $config, $prefix);
  </code></pre>
  
  <p>$application is always null, what is the purpose of using this approach. I tryied modifying it to </p>
  
  <pre><code>$var = JApplication::getInstance($id, $config, $prefix);
  </code></pre>
  
  <p>and returnig it but it doesn't work.</p>
  
  <p>I would be very glad if someone with more knowledge could explain what is happening here detailed as possible. Many thanks. </p>