Good way to make variables global (?)
| From: | Erica Douglass | Date: | Tue, 10 Oct 2000 00:04:52 +0000 |
| Subject: | Good way to make variables global (?) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-19264@lists.php.net to get a copy of this message | ||
I recently stumbled upon a way to make all variables global. I did this because I got sick of writing out global variable after global variable in my functions.
It seems to work just great in my script, but I wanted to read others' input on this. The advantages are obvious: no huge GLOBAL declarations. However, I wanted to know if there are any hidden pitfalls that I haven't noticed (besides the fact that a global variable could be easily overwritten.)
Here's the code:
function example_function () {
reset ($GLOBALS);
while ( list($key, $val) = each($GLOBALS) ) {
extract ($GLOBALS);
}
My impression: This is a very cool snippet of code... as long as you understand the implications.
Erica