Re: problem: creating global alias inside function

From: Date: Mon, 28 Jul 2003 15:19:35 +0000
Subject: Re: problem: creating global alias inside function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-157191@lists.php.net to get a copy of this message
* Thus wrote Ford, Mike [LSS] (M.Ford@lmu.ac.uk): > > -----Original Message----- rints 0, not 1 > > > > function setglobal(&$one) > > { > > global $globalvariable; > > PHP actually handles this by executing the equivalent of: > > $globalvariable = &$GLOBALS['globalvariable']; > > -- that is, it creates a $globalvariable *which is local to the function* > and makes it be a reference to the global-scope variable of the same name. > > > $globalvariable =& $one; Thus getting around the referenced global var, you can access the global directly: $GLOBALS['globalvariable'] = &$one; Tested: http://zirzow.dyndns.org/html/php/tests/misc/global_reference.php Curt -- "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#157191) next »