On Wed, December 19, 2007 8:18 am, Sancar Saran wrote:
> Thanks for response, I'm using this aproach maybe more than one year.
> I did
> not get any problems.
>>
>> there is no real difference between 'global $foo' and
>> $GLOBALS['foo'],
>> and the second is probably more maintainance friendly (as Rob
>> pionted out)
>
> Yes you are right writing global $foo in 25+ functions a bit
> problematic.


I don't see a problem with writing global $foo in 25+ functions *IF*
the variable really should be a global in the first place -- something
ubiquitous to the script as a whole, which is used everywhere, with a
distinctive variable name that you will never ever attempt to use for
something else.

>> that said, avoid globals like the plague - sometimes you may come up
>> with
>> a situation where using a global is really necessary - such
>> situations
>> should be the exception rather than the rule, often if your thinking
>> of
>> using a global there is another way of doing it. jmho
>
> And this is why I'm asking here, WHY I should avoid globals like
> plague ?
> Every one says bad. Alright, but no one says WHY ?

Because if you have too many 'global' variables running around, sooner
or later, you end up using the same variable for two different things,
and then suddenly your program misbehaves in ways that are impossible
to track down.

If you have ONE or TWO global variables, and you use them all the
time, and you know not to use that variable name for anything else,
*AND* you are not planning to integrate your code with another large
chunk of code, you're okay.

If you fail any of the above "if" tests, don't use a global.

-- 
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/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to