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