newbee needs help with some codes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mike.dang
Forum Newbie
Posts: 2
Joined: Wed Apr 22, 2009 4:24 am

newbee needs help with some codes

Post 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
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: newbee needs help with some codes

Post 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.
Post Reply