RE: [PHP] how to get var name and value from function?
| From: | Richard Lynch | Date: | Tue, 17 Apr 2007 00:18:05 +0000 |
| Subject: | RE: [PHP] how to get var name and value from function? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-253087@lists.php.net to get a copy of this message | ||
On Mon, April 16, 2007 12:10 pm, Ford, Mike wrote:
> No, not "just another array" (although I agree about the function
> being pretty useless!) -- $GLOBALS is a superglobal array that
> contains a reference to every variable defined in the global scope, so
> that accessing $GLOBALS['var'] from anywhere is the same as accessing
> $var in the global scope. It's a way of referencing global variables
> without having to use a "global $var" statement.
So, as far as I can tell, you're avoiding using the documented feature
"global $var" and cramming things into $GLOBALS which happens to work
but is an undocumented feature?
All the ills associated with "global $var" are still there, of course.
Or is it explicitly stated in the manual somewhere I'm not seeing that
one can put things in $GLOBALS directly? [shrug]
I'd just use "global $$var" personally, if I was gonna do this at all...
As a "middle ground" one could have a SINGLE global variable, say,
$DATA, and use the var names as keys in that...
Still not something I'd really recommend doing, but at least it's less
problematic than having a zillion global vars with generic names like
$name running all through your application.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?