Forum Moderators: coopster
For example, near the top of a script I'll usually define a variable like $PHP_SELF as a constant [define('PHP_SELF',$PHP_SELF);] so I can easily access it as a constant within a function.
However, because arrays like $_POST are super global, in the main script I can also put a variable like $PHP_SELF into the $_POST array; e.g., [$_POST["PHP_SELF"] = $PHP_SELF;].
It works, and it makes it very easy to extract all of the values in $_POST(++) in a foreach/variable variable line of code within a function. BUT, is there any downside to adding elements to $_POST? What's a better way?
Thanks in advance for your comments.
Salsa
Probably better than putting global functions in any of the pre-defined variables is just making your own array of globals your script uses and globalizing that one array name in the functions which need it. This just helps you keep your code straight and remember what's coming in from where.
However, your idea is interesting; I think many would think of this as 'sloppy coding', but if it's your own code and you really know what your doing with it, yeah, this might save you that little bit of time. A downside of it is that you'll really have to beef up security. E.g., if you're extracting every value in POST automatically, and somebody issues an HTTP request to your file with POST values in a hacking attempt, you could be set for problems. In the long run it will probably be easiest to keep your code secure, legible, and maintainable just by using conventional coding practices.