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> }

?>>
Now that I read what you really want :)

You can use a class to track a variable which may achieve what you
want like this:

class globalvariable {
        var $gv = 0;
        function globalvariable(&$var){
                $this->gv =& $var;
        }
}
$one = 1;
$g = new globalvariable($one);
echo 'global '.$g->gv.'<br>';
$one = 2;
echo 'global '.$g->gv.'<br>';

-- 
regards,
Tom


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

Reply via email to