Variables in PHP are case sensitive. That means if you code a variable with some capital letters and some lower case letters you must code the variable the same exact way throughout your code, or your code will break.This can cause hours of headaches when debugging code if you do not choose a naming convention when programming and stick to it.
I'm as guilty as anybody when naming variables using multiple cases. I've also spent hours hunting down a bug in my PHP code only to find the problem was the case of a variable was mixed instead of all lowercase.
The solution to your naming conventions is simple: Pick something and stick with it.
You can use all uppercase, all lowercase, capitalize the first letter of the word. Whatever floats your boat. Just remember to make a variable naming convention that addresses case sensitivity and always follow it.
My personal favorite now is to only code variables in lower case only. How do you name your variables?
koen (103) says on October 30, 2007:
Mark, I always do only lower case, and I try to always give a variable a meaningful name. Lucky as I am, I've never had headaches because I had troubles with variable names. My mistakes are usually in wrong if-statements, or giving variables the wrong value (TRUE or FALSE for example.)45n5 (946) says on October 30, 2007:
i used to capitalize the first letter like MyVariableunfortunately this was stupid and any time I use a module, function, or snippet of code from previous projects i'm forever checking for this now.
hopefully moving forward I get squared away.
yeah. all lowercase is the easiest ;-)
PHP eBook says on October 31, 2007
I also go with all lowercase. Sometimes you are working with a script written by someone else and must adjust... Also I've found that a lot of scripts use captials or underscores, so using all lowercase with no underscores tends to keep conflicts to a minimum.
-Chris
45n5 (946) says on November 1, 2007:
@PHP eBook - thanks for stopping by. I wish I would have known the lowercase thing when i started ;-)sarahG (34) says on November 9, 2007:
I used to use just lowercase, sometimes with underscores. Now I have a habit of all lowercase but if I need to make it a little more readable I'll give the second word a capital letter. I'm sure it'll change again soon ;)Taking over other people's work I've found the most annoying part to be where they capitalise the first letter of their field names in the db tables.
koen (103) says on November 9, 2007:
"I'm sure it'll change again soon ;)", and that's what part you shouldn't do Sarah ;) if you keep changing it, you might find yourself making mistakes when re-using old code, or at least, have to go through the script again, and see what variable style you used.sarahG (34) says on November 10, 2007:
I've not found it to be a problem yet ;)Also, by altering your style every so often it means you take a good look at your old code that you perhaps want to reuse. I probably renew my old code with improvements every 6 months. Code from when I first learnt PHP several years ago is completely different to what I use now. Simple things like a change of a function because it's more comfortable, easier to read and faster to use than the previous one etc.
The change in variable style is not dramatic and to be honest every change is an improvement in my eyes. If I had the time I'd go through any older code and bring it up to speed, but that's only done when it's paid for ;)
By the way, your comment and post feeds still have the backslash escapes in them. In case you didn't realise :)
koen (103) says on November 10, 2007:
I can't change the feeds, I'll mail Mark though.45n5 (946) says on November 10, 2007:
fixed it ;-) thanks for the heads up


