Re: Easier way to clean GET Variables ?
| From: | Burhan Khalid | Date: | Thu, 25 Aug 2005 08:37:32 +0000 |
| Subject: | Re: Easier way to clean GET Variables ? | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-221339@lists.php.net to get a copy of this message | ||
Jasper Bryant-Greene wrote:
Burhan Khalid wrote:This is exactly the reason why you shouldn't do it. You don't know when PHP might come out with a new 'superglobal' that conflicts with your $_Myfunc. In addition, when PHP prepends $_ to a variable name, it means something. Specifically, it means that the variable is a 'superglobal'. The only exception to this that I know of is $GLOBALS. For the reasons above, I avoid creating user variables with $_ -- although there is no rule regarding variable names (other than the syntax rules). Sometimes, just because you can do something, doesn't mean you should. Regards, BurhanJasper Bryant-Greene wrote:Would you care to elaborate with some reasons for this? I find it very useful as a naming convention for any sort of "external variable" or user input, so when reading my code I can immediately tell what came from where. Prepending the variable name with an underscore happens to be what PHP does ($_SERVER, $_GET, $_POST, $_COOKIES, so on...) so it is simpler just to carry on that convention.Robert Cummings wrote:I would also in a real script, not use $_MyVar.[snip] Still need to check isset() status unless you've disabled E_NOTICE which I don't advise since it's sloppy ;)Yeah, I usually would in a real script. Just slipped my mind when writing that example.