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
newbee needs help with some codes
Moderator: General Moderators
Re: newbee needs help with some codes
& 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.
:: 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.