Re: Global Variables -- why not have them?

From: Date: Sun, 08 Jul 2001 11:50:29 +0000
Subject: Re: Global Variables -- why not have them?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-56749@lists.php.net to get a copy of this message
Hi Mitch! On Sat, 07 Jul 2001, Mitch Vincent wrote: > I appreciate the reply, thanks.. > > However, I think you missed my question. My question is a why, not a how > question.. It's a language feature I've come to count on with the other > languages I work with (C, mainly), and I'm wondering what prompted the > decision to move towards having to specify global variables (and essentially > eliminating global variables). > Working w/ global vars in C is a known bad practice, so PHP doesn't encourage it. You must see a php file as a sort of namespace, or an analogy with C would be that every time you use a variable it defaults to "static" not "extern". In C you have a lot of madness with name clashes, and have to be very organized and prepend your variable names with a "key" acting as a namespace surrogate. PHP was thought to be easy to use and to help newcomers avoid common mistakes. You must learn it's way if you want to be effective. Also take a look at design features proposed for PHP5. Looks promising and more C++ like, so better compare it with the later one. and BTW, it's quite easy to say $foo is to be a global var, and the fact that the keyword "global" appears right there in the code is a *good thing*(tm) cause it prevents baldness ;) cheers, -- teodor

« previous php.general (#56749) next »