Re: [PHP] Opinion about the using $GLOBALS directly



Hello Jochem,

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.

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 ?

I try to use alternative ways. But maintenance, complexty and speed costs much
too high.

I did not see any benefit.

Robert Cummings says to "you may confusing to setting variable". I have some
debugging methots to detect this.

And Of course I did not use someting like for($GLOBALS['i']=0;....

And I use GLOBALS for everything for I need someting more than once. (Db
pointer or config array etc).

Thanks for response

Regards

Sancar
.



Relevant Pages

  • Re: Any Clojure users here?
    ... Collections.sort(foo) => ... Clojure is a Lisp-1, so there is only one fundamental operator (special ... Clojure's defn is a macro that wraps def; ... dereference than globals (because globals are ...
    (comp.lang.lisp)
  • Re: defvar affecting captured closure variables ?
    ... ignore the advice about global lexicals. ... | bind these globals, since otherwise you'll get a lexical foo when you ... | bind foo. ... again distracting as ar esult). ...
    (comp.lang.lisp)
  • using "our" across blocks
    ... I want to double-check that it is correct to use "our" to import globals. ... our $foo = 'foo'; ... ...at this point I can see 'foo' and 'bar' values. ... Global symbol "$foo" requires explicit package name at ./script.pl line xx. ...
    (perl.beginners)
  • Re: Rebindings [was Re: Favorite non-python language trick?]
    ... oops, for below example, needs global declaration ... def foo(): ... So that limits it to the local scope and nested scopes and declared globals not ... preempted by nearer nested scope variable names. ...
    (comp.lang.python)
  • Re: Using an object inside a class
    ... Then you probably should not be using globals. ... But this tells me "global name foo is not defined": ... going on here is that you're assigning foo somewhere inside method1 ...
    (comp.lang.python)