Page 1 of 1

general function question

Posted: Wed Oct 10, 2007 10:35 am
by mad_phpq
why does this function have an ampersand at the beginning of its name?

Code: Select all

function &varSession($name)

Posted: Wed Oct 10, 2007 10:54 am
by mad_phpq
i've found an answer, but i have another question.

The ampersand return the reference to the value in the function rather than the value itself. Why would it be used in this code below.

Code: Select all

function &varSession($name)
{
  global $sessionPrefix;
  return unmagic_quote_gpc($_SESSION[$sessionPrefix.$name]);
}

Posted: Wed Oct 10, 2007 11:58 am
by feyd
Probably because the function being called internally returns a reference.

Posted: Sun Oct 14, 2007 6:59 am
by mad_phpq
feyd wrote:Probably because the function being called internally returns a reference.
whats the benifit?

Posted: Sun Oct 14, 2007 9:45 am
by RobertGonzalez
References have been the subject of many a coder's nightmares. My suggestion would be to set up a PHP4 and PHP5 environment locally then do some of your own reference tests. This is pretty much the best way to get a hold of references and their uses/benefits/drawbacks to you.