Naming Variables - Introduction
This is a small and basic tutorials on how to name your variables... what you can, and what you can't. This could be important.
Please take note, that these rules that apply to naming your variables could very well apply to other naming rules such as naming functions and classes (covered in a later tutorial).
What to do/Not do
Names of variables, functions and classes are to start with a letter... any letter from a to z or A to Z or an underline but no numbers and definately no signs. Below is a list of example names that are correctly named and incorrectly names.
$Al34n_3
- Correct
$_3fg
- Correct
$3fv_f
- Incorrect
$fg_#t
- Incorrect
function _()
- Correct (Yet, I don't recommend it)
The only characters allowed in variable, function and class names are any letters (lowercase or uppercase) or and underline followed by any numbers. Of course you could only have letters or letters mixed with numbers or underlines.
Even though you can have a function named _, I don't recommend it... why? Well, this brings us to the next section.
Naming Variables, functions, classes
The reason I don't recommend you to name a function simply by an underline (_) is because it doesn't describe the function any. I recommend you that you name the variable, function, or class in a way that describes what it's holding in one or two words... that is where the underline comes in.
Lets say that you have a variable holding someone's name... you wouldn't name it $city would you? (Unless it's a city's name), you would name it either $persons_name or simply $person...
Conclusion
Well, I hope that you learned the correct way to name your variables, functions, and classes correctly in this short tutorial. Take care 🙂
This page was published on It was last revised on