PHP: Most Common Mistakes (part 1) – Not Learning the Basics

Posted: April 11th, 2011 | Author: | Filed under: Common PHP Mistakes, PHP, Programming/Development | 1 Comment »

I am starting my blog with a series of posts on common mistakes that PHP developers make. I have been studying PHP for about seven years and throughout that time I have communicated with many other developers, or aspiring ones, via programming forums and other avenues. I quickly learned that most beginners are bound to make a series of similar mistakes, and even veterans fall into similar groups of traps. I know that when I began doing PHP, I made many of the very mistakes that I am going to discuss in this series of posts. I hope that my trials and tribulations will save some aspiring and even veteran programmers some valuable time.

The Problem

I decided to begin this series with the problem of beginners “not learning the basics” because it is by far the most frequent mistake I see made. Not only that, but it also serves to be the most damaging for a developer since everything they do after this blunder can be for naught if they aren’t careful. Even though this issue is ramped, it is an easy one to avoid and I will discuss how a little later.

This problem amongst PHP developers who are just starting out is simple to understand. It comes down to the developer trying to tackle large and overly ambitious projects before they even know the low-level basics of the language. I realize that this problem can be found in the students of any programming language in existence, but I contend that this mistake is by far the most prevalent within people trying to learn PHP. I say this because of the incredibly colossal amount of PHP resources that are available all over the web.

From what I have seen and from what I did myself, someone first aspires to learn PHP when there is a specific project they want to work on. For example, someone who has had some experience building static websites in pure HTML decides they want to make a forum. They have read before that PHP is a good scripting language for writing forum software. Even though this is true, it is only true for a developer who has mastered PHP. As for the beginner, from what I’ve seen time and time again, they will just go to their favorite search engine and input a search along the lines of, “making a forum with PHP”. This is where the disaster begins. From that query, the searcher will be shown many relevant results. Some will be good and some will be bad. Either way, the aspiring developer, who might have decided 15 minutes ago that they wanted to learn PHP, is thrown into what I like to call “copy and paste dev mode.” From this point on, their only method of writing PHP code will be to first find a tutorial on what they are trying to write, and then copy and paste either pieces of it, or maybe even the entire thing. In the end, until someone more experienced points them in the right direction, this will be their sole method of PHP “development.”

Why is this a Bad Mistake?

I consider this the worst mistake a beginner can make because it more or less assures they will never actually learn and understand PHP. It is difficult to convey how many times I see questions like “How do I make a forum?” or “Why won’t this code work?” Questions inquiring as to why an entire PHP script won’t work are mainly proposed by people who simply copy and paste and have no knowledge of the language. This example depicts one of the main problems with someone failing to learn the basics of the language. They never develop any knowledge to be able to work with the code they find online. They are completely bound by what others have written and posted. Even worse, since there is such a wide range of code out there from PHP developers of different skill levels, a lot of code examples and scripts that can be found on websites are poor to start with. This means that even if the aspiring developer tries to learn via the code they’ve copy and pasted, there is a very real possibility that they are learning from incorrect or inefficient code.

The Solution

If you are looking to start learning PHP, my first piece of advice is to go to your local bookstore and pick out a PHP book for beginners that you find to be an effective teacher. I always recommend physical books to beginners for a few reasons. First and most importantly, it is much more difficult to find a poor book that is published on PHP than it is to find a poor tutorial online. Anyone can post his or her code online, whether it is good or not. As for a book, at the very least the author has to get a publisher to invest money in it and then get it on store shelves. This provides some quality assurance. The other reason I prefer recommending physical books to novice PHP developers is that I think being able to sit down and read a book allows them to keep pristine focus on actual learning. If you are reading online tutorials, I feel attention is constantly shifted by other elements on the page and people can be compelled to move on to other subjects before mastering the one they were working on.

Once an individual has a firm grasp over the fundamentals of PHP, I think there is a ton of knowledge that can be gained from online resources. Someone with experience, unlike a beginner, can fairly easily sort over information found on the web and quickly identify what is valuable and produced by a knowledgeable developer compared to a resource that was put out by someone who is an inexperienced beginner. With this important ability to assess the quality of resources, you can find great PHP resources on the internet. With that said, what you find online should mainly be in the form of individual functions or individual pieces of code that accomplish a very specific task. An example of what I consider a valid use of online resources is an email address verification function. An experienced developer would say something along the lines of, “I want to write a function that returns true if it thinks an email address is valid and false otherwise.” You know exactly what you want to accomplish and you would be able to write it in some form on your own. However, many factors determine whether an email address is valid or not. Most people, even highly experienced developers, cannot account for every aspect of a valid textual email address string. This is a situation where it is of great value to see how other developers have studied email address formation and check out some of their solutions on textual validation.

Conclusion

PHP is an awesome language and it isn’t terribly difficult to learn. It is just important to always ask yourself if you can solve problems with your knowledge of the language and not just accomplish variations of what you’ve already done. In reality, if you have firmly grasped the fundamentals of PHP, there shouldn’t be many tasks you can’t complete. Always remember that online resources are valuable, but their usefulness should be left to aiding you with ideas and theories for very specific functionality.

One Comment on “PHP: Most Common Mistakes (part 1) – Not Learning the Basics”

  1. 1 Eldor said at 7:36 am on August 13th, 2013:

    Well said! That’s what I’m experiencing for the last four monthes. Although, i recommend to start from more interactive learning facility rather than physical book, just to get the ball the rolling. Afterwards, dive into one of the best php books printed out there.


Leave a Reply