PHP is a very simple language to learn. It’s loose data types and plethora of examples on the web make the cost of entry to PHP development very low. It also empowers new programmers to venture out and get cracking on their own projects. I admire the efforts of these new programmers, but I also think that choosing PHP as their starting point is going to bite them in the butt in the long run.

Like having just enough rope to hang yourself, figuratively of course, PHP provides you just enough rope to develop some very bad programming habits. As a product of a University Computer Science program, I strongly believe that some level of professional or formal instruction is paramount to being a good programmer. There are exceptions to all rules, and especially this one, but by and large most people don’t see programming best practices as common sense so they must be taught. Here are a few tips that I think early programmers should be firmly familiar with:

1. Watch your datatypes – PHP supports loose variable declarations. What this means is that can change a variable’s datatype on the fly based on whatever you are assigning to it at the current time. While this is nice and prevents you from having to declare massive lists of variables, do not get into the habit of reusing variables for numerous purposes in your code. A variable named $count should be used for it’s initial purpose as a counter and not used later to store some other bit of data such as a name or other string.

2. Pick a variable naming standard – PHP allows you to name variables just about anything. There are a few exceptions to this that are explained over on Keep in mind that variable names in PHP are case sensitive. One mistake that you will want to avoid in variable naming is mixing and matching your variable naming scheme. By this I mean, choose a method for utilizing case or underscores when creating variable names. $my_variable_name and $myVariableName are both acceptable and easy to read variable names. The latter is an example of Camel Case and is the method that I use for naming all of my variables. Either method is fine, but pick one way and stick with it. When working on a group project, discuss this with your fellow programmers and set a standard for the project to avoid inconsistencies.

3. Don’t be afraid to ask for help – There are a huge number of development forums filled with some very experienced programmers that are more than happy to lend new coders a hand. Don’t be afraid to ask them for advice. They have a lot of wisdom to impart and they can be a great source of information. My personal favorite is the PHP forum over at DevShed.

4. Just because  you saw it online doesn’t mean it’s good code – There is a lot of bad PHP floating around and there are a lot of well intentioned people out there passing this bad code off as a good source for learning PHP. Don’t be sucked into that cycle. Try to keep your resources to some of the more mainstream PHP sites like PHP Builder, DevShed, PHP Freaks, and the W3 Schools website.