PHP static function self:: in joomla JFactory class explanation?

Posted by Carbon6 on Stack Overflow See other posts from Stack Overflow or by Carbon6
Published on 2012-11-01T20:04:45Z Indexed on 2012/11/01 23:00 UTC
Read the original article Hit count: 235

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about class