I noticed that variables like $_GET are available everywhere in the program. They are different from global variables (these need to be defined 'global' in a function)
What exactly is the difference between them and can i define variables like $_GET, so I don't have to define them in each function ?
it does explain how to use it, but doesn't mention anything about global variables.
I want to know more about this variable compaired with global variables; you have to agree global variables and (for example) $_GET look like globals, but $_GET is different
One caveat: if you make a function dependent upon $GLOBAL, it is effectively the same as using a "global" variable declaration within the function: it is now closely coupled with the application code and thus inherits all the same problems that cause most developers to eschew the use of "global" (re-usability issues, testing issues, potential for nasty bugs issues, etc.)
The "standard" super-global arrays such as $_POST and $_GET aren't quite as bad, as they are, well, standard. But even then using them directly within a function may be less than desirable, as opposed to passing the necessary variables in the function parameters, whether by copy or by reference.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
One caveat: if you make a function dependent upon $GLOBAL, it is effectively the same as using a "global" variable declaration within the function: it is now closely coupled with the application code and thus inherits all the same problems that cause most developers to eschew the use of "global" (re-usability issues, testing issues, potential for nasty bugs issues, etc.)
The "standard" super-global arrays such as $_POST and $_GET aren't quite as bad, as they are, well, standard. But even then using them directly within a function may be less than desirable, as opposed to passing the necessary variables in the function parameters, whether by copy or by reference.
I won't say never, ever use them; but generally speaking it's almost always better not to in terms of re-usability and all that other stuff. About the only time I'd say not to worry about it is if you are writing a quick, one-off script that you never expect to re-use in any way or have to maintain.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks