Re: Opinion about the using $GLOBALS directly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sancar Saran wrote:
> 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 ?

Well for one thing it makes things harder to trace. You look at some
code and you're just using some magic global variable. You can't tell
what kind of object or variable it is just by looking at the code.

There is also the chance that a mistake or some malicious code could
overwrite you're global variable which could be hard to find/stop (one
reason to ALWAYS put the constant on the LFH of the if equality test:
if('somethine'=$var) gives a syntax/compile time error but
if($var='something) is syntactically fine and often hard to spot that
the extra = is missing).

There is also the namespace issue. If you have a very cluttered global
namespace and you try an merge in some other code with your which also
uses global variables they may end up clobbering each other. You should
definately always use a code-wide prefix on all global variables to try
and reduce the likelihood of this happening.

Col.

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux