Forums

equal ampersand

?
Guest 13 Aug, 2011
Hi all,

to the best of my knowledge equal ampersand (=&) is being used to reference methods (or variables)

therefore:
$db =& JFactory::getDBO();

would reference an exisitng db connection (created by Joomla)
while
$db = JFactory::getDBO();

would create a copy of an existing db connection which means additional db connections without them ever being closed
logging in to server / phpMyAdmin in this case might result in errors like: connecting to db failed / too many connections / #1040 Cannot log in to MySQL server

$user =& JFactory::getUser();

would reference the current user
while
$user = JFactory::getUser();

would create a copy of the current user which would create additional sessions

looks to me like there is a prob in CF as all occurances of JFactory::getUser() and the majority of occurances of JFactory::getDBO() appear without a preceding ampersand.

please correct me if my aasumptions / conclusions are wrong.

J!1.5.23 CF 4 RC2.0
GreyHead 13 Aug, 2011
Hi gabrielaH ,

You'd need to ask Max about whether this is a deliberate choice of his or not.

In practice I think that (a) in PHP5 most object are passed by reference regardless of the & and (b) any extra instances will be closed by the garbage cleaning when the containing function or class is closed.

Bob
This topic is locked and no more replies can be posted.