Re: Symbolic References and the global namespace

From: Date: Mon, 28 Feb 2000 18:27:48 +0000
Subject: Re: Symbolic References and the global namespace
References: 1 2 3  Groups: php.pear 
Request: Send a blank email to php-pear+get-34@lists.php.net to get a copy of this message
Sterling Hughes wrote: > > I am developing a function for PEAR that will automatically load configuration files > into PHP, anyway, I want to make the configuration options variables in the global > namespace however in order to this I assume you would have to do the following: > > --short example-- > > class Bar { > function set () { > $name = "Sterling"; > $GLOBALS[$$name] = "Hughes"; > } > } > > Bar::set(); > print $Sterling; //I'll save you the suspense it prints nothing, nada, zip, ... > > -- End Short Example -- > > Is there any way to achieve the desired affect (or should I request this as a > feature change)? You're making this harder than it is. Your $GLOBALS assignment should be just $GLOBALS[$name] = "Hughes". Try "dereferencing" your variable variable like this: $GLOBALS[$$name] == $GLOBALS[$Sterling] = $GLOBALS['']. So it's no big surprise it prints nothing. :-) - Stig

« previous php.pear (#34) next »