Re: PHP globals aren't really globals
| From: | Thierry Coopman | Date: | Wed, 14 Feb 2001 14:39:09 +0000 |
| Subject: | Re: PHP globals aren't really globals | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-39625@lists.php.net to get a copy of this message | ||
At 11:24 AM -0300 2/14/01, Christian Dechery wrote:
I've been programming in C all my life, and now I just started developing in PHP and I'm really enjoying it, it has all the missing improvements that C needed to be more user-likely. But one thin I can't get, how can PHP call a variabel global, if it isn't global. A global var, is a var defined outside all functions and it's available to all and altered by all, without having to redefine or call the var again. In PHP, for a var to be global you have to add a 'global $var' inside the function u want to use it. THis is not nice, what about if u have a form with 50 fields and want a function to validate all of them, u have to pass them all to the function or build a little piece of code to make all th $GLOBALS local right? Is this really the idea of global vars?Well having a form with LOTS of fields, it might be advisable to have the fields send an array straigt away have the name of your fields something like <.. name="feedback[name]" ..> and just use global $feedback and the whole array is at your disposition. This doens't change the way global is treated in PHP but might help you in your setup. having these in an array will also greatly make sessions easier, if you have to follow all these fields on multiple pages. -- Thierry Coopman - thierry@keytrade.com My opinions are personal, and have really nothing or nothing to do with Keytrade! He who laughs last probably made a back-up.