Hi,

Tuesday, July 29, 2003, 12:32:33 AM, you wrote:
MP> The following code illustrates a problem I've got with references (running
MP> on PHP 4.3.2).  Can anyone explain it for me?  Thanks in advance for any
MP> assistance!
MP> Martin

MP> <?php

MP> $globalvariable = 0;
MP> $one = 1;

MP> //want to set up $globalvariable as a reference to $one
MP> setglobal($one);

MP> echo $globalvariable; //prints 0, not 1

MP> function setglobal(&$one)
MP> {
MP>       global $globalvariable;
MP>       $globalvariable =& $one;
MP> }

?>>

You don't need the =& in the function as you are passing a reference
already. So you are setting $globalvariable to point to a reference
that is pointing to $one. You just need:

function setglobal(&$one)
{
      global $globalvariable;
      $globalvariable = $one;
}



-- 
regards,
Tom


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to