Jasper Bryant-Greene wrote:
Burhan Khalid wrote:
Jasper Bryant-Greene wrote:
Robert Cummings wrote:
[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.
I would also in a real script, not use $_MyVar.
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.
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,
Burhan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php