I am using joomla and that i read with the API and that i observed the JFactory class getting functions return a mention of object however the good examples I've collected from the web don't use the & while using the functions.

Say for instance the Jfactory::getSession() which returns a mention of global session. the documentation implies that its understood to be function &getSession(params){code} - clearly determining a reference return. however, in this example, they refer to it as as $session = JFactory::getSession(); should not it's $session =& JFactory::getSession();?

It states within the php documentation that there's an & within the function as well as an =& within the caller. I've also been through C programming and when I miss such things as this, you will see errors like "invalid pointer conversion" - which isn't a great programming practice to tolerate.

What may be the proper practice?


i personally use joomla 1.7 and i am developing a component. sometimes on xampp with php 5.3.8

It is dependent on:
- the version of Joomla and also the version of PHP you utilize
- what returns the JFactory::getSession() method

Joomla version 1.5 works with PHP 4 and PHP 5, versions 1.6 and 1.7 are just suitable for PHP 5.

When the method returns an item, the & is required in PHP 4: automatically, objects are passed/came back by value (a duplicate from the object happens). The & eliminates the copy.
In PHP 5, the & is useless : objects will always be passed/came back by reference (no copy happens).

When the method returns other things, the & should not be utilized but could be helpful in certain unusual cases (to be able to save memory for those who have an enormous array or string, for instance, and you wouldn't want of copy of these within the assignment).

The great practice would be to always put a & in assignment once the method signature features a & too.

Inside your situation, I believe that you are using PHP 5 along with a recent version of Joomla, so avoid using & : this really is most likely an obsolete code in Joomla sources.