Page 1 of 1

newbee needs help with some codes

Posted: Thu Apr 23, 2009 11:54 pm
by mike.dang
Hi,

The following snippet is from Joomla:

$mainframe =& JFactory::getApplication('site');

What do =& and :: mean?

I know this is php using OO, but why can't it be used the following way?

$mainframe = JFactory->getApplication('site');

TIA

Re: newbee needs help with some codes

Posted: Fri Apr 24, 2009 4:30 am
by php_east
& refers to the reference, not the object itself.
:: refers to the class method, as compared to the method of an object of the class, as in your example ->.

in other words, $mainframe =& JFactory::getApplication('site');
refers to class method, not an object method. it means you do not need an instance of the Factory object to use it.

$mainframe = JFactory->getApplication('site');
is invalid.

$mainframe = $factory->getApplication('site');
would have to be preceeded with
$factory = new JFactory(); but that would be wasting space since or if you do require $factory. JFactory is huge i think.