I’m planning to expose some common variables as globals in my script and am wondering if the following naming scheme would be considered bad ideas:
- using single underscore at the beginning and end like:
$_some_var_ - using triple underscore at the beginning like:
$___some_var
I know that php uses single underscore at the beginning for superglobals and double underscore for magic methods so there shouldn’t be any conflicts. Is there anything else that could cause trouble? And is doing this considered bad for any other reason?
Thanks!
It won’t cause any problems per say. For ease of typing you may just want to go with the single underscore.
In my app, if I must introduce such globals that I may use in many scripts both inside and outside of functions, I use the
$GLOBALSsuperglobal so it is very apparent that the variable being accessed is a global.This also saves having to use
global $somevar;in functions. But it is a lot more typing depending on how often you use them.Could the values possible be constants or are they actually variable?