Before you start learning PHP, it might be wise to plan your approach to learning the language.
Professional developers who learn PHP have spent a significant number of hours learning their craft. To emulate them, you’ll need to make sure you’re motivated to do the same and ideally able to learn PHP quickly and efficiently. The slower and more inefficient your learning methods are, the longer it will take you to land a PHP development job or build the app you have in mind.
An even worse consequence of a slow and ineffective approach to learning is that you are more likely to drop out! Research by Harvard and MIT found that only 4% of students who enroll in online courses complete them.
So how can I help you avoid becoming another of the 96% of people who give up?
I have compiled a list of 10 tips to help you learn PHP. These tips should help you approach learning PHP effectively, keep you motivated, and also avoid some potential pitfalls.
Let’s get straight to them!
Tip 1 – Be sure you want to learn PHP
If you came to this article as a newbie to programming, you may not have a strong preference for which programming language to learn. While this isn’t necessarily a problem, it can lead to a problem later when you realize that another programming language is better suited to your aspirations.
PHP is a server-side programming language commonly used in web application development; if you realize in a few months that what you really want to do is work at Rockstar and help build the next edition of Grand Theft Auto, then you would be better served learning a programming language commonly used in game development, such as C or C++ . There are many great reasons to learn PHP, including:
- Want to take your WordPress knowledge to the next level? As of September 2018, 7% of all websites use WordPress. Since WordPress is powered by PHP, it creates a huge demand for PHP skills. And if you would like to use other content management systems such as Joomla or Drupal, I am happy to tell you that they are also built on PHP.
- PHP is considered relatively easy to learn compared to other programming languages.
- Because PHP is native to the web, you’ll be able to put simple projects online much faster and with less difficulty than you would be able to with some other languages, which means you’ll see the results of your efforts much faster than if you had to learn another language .
So before you start learning PHP, make sure you consider them so that you can be sure that PHP serves your needs.
Tip 2 – Keep your projects in mind
Now that you know why you want to learn PHP, it’s also helpful to have a goal in mind, what you want to do with it. Learning PHP will be a long process and staying motivated will be easier with the end goal in mind.
Online courses, such as Udemy’s Learn PHP Online course, keep the learning process interesting and interactive by allowing you to create a project as you learn the basics of PHP development. This is a great way to make the learning process interesting and understandable, but even better is to keep the idea of your project in mind. If you keep your project in mind, you’ll be more motivated to remember what you’ve learned if you want to apply it to your project.
You’ll need to keep practicing your newly developing PHP skills, and it’s usually easiest to motivate yourself to work on your project. You can even create different versions of your project as your skills develop. For example, you could initially create a simple contact application that has basic functionality for adding and removing contacts.
As your skills develop, you can add it to the database. You can add more advanced features later before launching and inviting your friends to submit their details. Before you know it, you could be the owner of one of the largest social networks in the world, connecting over a billion people and generating billions of dollars in advertising revenue. Who knows?
Tip 3 – Learn HTML first
While PHP is a great choice as your first programming language, it should not be your first step into web development. If you haven’t already, you should spend some time learning HTML before learning PHP.
HTML is a markup language rather than a programming language that forms the basis of web pages. This means that the code you write represents the basic elements of a web page, such as images or text. You can’t program any functionality with a markup language, which makes it relatively easy to learn, and it also created the need to use a language like PHP alongside HTML to make websites more dynamic.
Because PHP is generally used to make HTML dynamic, HTML is commonly found in PHP documents. HTML will not only be present in most PHP applications, but will also be part of many PHP development tutorials and lessons. Most of these tutorials will simply assume that you already know HTML.
So instead of learning both at once, spend a few hours learning the basics of HTML. It will take months to learn PHP, but the time it takes to learn HTML is a matter of hours.
Tip 4 – Active learning over passive learning
One of the best ways to make learning more effective is to learn actively rather than passively. Passive learning means simply watching/reading/listening and absorbing information. Active learning means applying what you learn to a problem or project.
Educational experts seem to be united in their belief that active learning strategies are better than passive ones. The only problem is that creating an active learning experience is generally more difficult than creating a passive one.
An example of passive learning is watching a YouTube video of an instructor giving a presentation explaining what the features are. However, passive learning experiences can still be useful. The instructor can offer the best explanation of what a function is that you’ve ever heard.
The recommendation here is not necessarily to avoid passive learning experiences, but to try to activate them. You can take the examples in the lecture and write them yourself, make changes and see what happens.
Tip 5 – Don’t be afraid to break things
Be careful with this advice. If you’re working on a live site, purposefully breaking things is definitely not the best idea. If you’re working with WordPress, it’s generally recommended to leave PHP files alone in WordPress core. Don’t break them. But it’s not a bad idea to break things in the offline project files you create, or in the PHP files in your WordPress theme folders.
You learn a lot when you put them together. This advice doesn’t strictly mean that you have to crash your website, but rather that you shouldn’t worry about it happening. Things that go wrong are generally a great learning experience. The bigger the problem, the better you remember the solution.
Tip 6 – Turn on Error Reporting in PHP.ini
If you’re going to screw something up, it might be wise to make sure error reporting is enabled. This may be enabled by default, but in some cases when you crash a PHP application, you’ll just see a blank screen. To display the error message, make sure you enable error handling in the php.ini file with the code: ini_set(‘display_startup_errors’, 1); ini_set(‘show errors’, 1); error message(-1);
This means that when you make a mistake in your code, an error message like the one below (the result of a missing semicolon) will at least return a somewhat useful message to help you debug the problem.
Tip 7 – Be careful with syntax
Both in your coding education and in your life as a professional developer, you will lose hours of life due to syntax errors. A syntax error means you wrote something that PHP didn’t understand. This could be because you spelled the variable name differently than you created it, or you forgot to put a semicolon at the end of your statement. You’re going to forget that semicolon a lot.
In other situations, one missing semicolon will terminate the entire application. So be very careful with your syntax. When programming, it is necessary to spell things correctly. But this knowledge of the probability of syntax errors is useful. It tells us where to look first when your program isn’t working. Before deleting the entire program and running it again, check for syntax errors.
Tip 8 – Keep your code readable
As you learn to code, you will learn from instructors who take great care in presenting their code. And if you’re not… you should find another instructor. At first, all the spacing, indentation, and alignment may seem superficial.
If the code works, it works, right? Who cares about spacing? You won’t care when you make a mistake or go back to review code you wrote a while ago. Even worse, if your colleagues have to work with your code that you didn’t keep readable, you’ll worry even more because your colleagues will hate you.
Well-written code is essential to solving the errors described in tip 7. If you put all your code on one line, the computer will be able to read it just fine. But if you’re missing a semicolon, you or someone else has to figure it out. In which example would it be easier to find the missing semicolon?
In case it’s not obvious, it’s the same code. The only difference is the spacing. The first version of the code makes it easy to spot the semicolons at the end of each line, while the HTML span tags and PHP’s opening () tags in alignment also help identify if you simply forget to add a closing tag.
The second version is just all the code thrown together. Now you have to check your entire code for potential missing semicolons rather than just a quick look at the end of the line. Where do PHP tags start and end?
They have their lines in version one, but you have to scan the entire code from the opening tag to the closing tag in version two of the code to check that they are both there.
In addition to keeping your code clean, clear, and readable, be sure to use comments to remind you of what you were thinking when you wrote the code. Comments are lines of text that are ignored by the PHP interpreter. You can turn your text into a comment by adding two slashes at the beginning of the line.
// Like this.
The computer completely ignores your comments, making them seem meaningless. But while code is for the computer, comments are for humans. Especially if you’re writing something complex, comments can be very useful in the future for other people or for you to understand or remember what your program is doing. For example, below I wrote a comment above this custom WordPress query to remind me what it is when I learned it. A comment is gray text that starts with //.
Comments can be a great way to leave little notes to help you remember how to do things. As a novice, it’s very likely that you’ll revisit the code you’re writing now in the future. When someone asks you to build something you’ve already built, it can be easier to refer to code you’ve written that you previously understood rather than trying to understand someone else’s example you found via Google.
Well, it will be easier if your code is clean, clear, understandable and makes good use of comments.
Tip 9 – Try to solve problems yourself
When you encounter a problem, a common response is to immediately ask for help.
Now, there is nothing wrong with asking for help. Many people would say it should be encouraged. But if you ask someone once you’re stuck, you won’t learn the lesson nearly as well as you would if you figured out the problem yourself. It’s the right time to ask the question.
This might seem like more of a problem at a real-life coding bootcamp, rather than online, because at a bootcamp you can raise your hand and ask the instructor for help.
But remember, learning PHP doesn’t break the bank – you’re not the first to learn this programming language.
Many people have gone before you and their questions are all over the internet. There are also plenty of people who want to help, and their answers are also all over the internet.
Especially if you’re early in your learning experience and learning the basics of PHP, it’s extremely unlikely that someone else hasn’t encountered your problem before. So if you want to find the answer to any problem you have with PHP, do what you do to solve all your other problems. They googled it!
At the top of the search results, you’ll find that someone has probably posted an eerily similar question to yours on Stackoverflow.
If you can’t find a match to your question, it’s also worth remembering that PHP, like any other programming language, has extensive documentation to help its users understand how to use PHP. If the manual is a bit overwhelming, there is a more digestible PHP knowledge base available on BitDegree.
Tip 10 – Understanding jargon
One of the difficulties you may encounter in the beginning when learning PHP is the technical language used by your instructors or in the instructions.
A good instructor will be able to explain the basics of PHP in plain English. But as you get to more advanced topics, the instructor will need to use more technical language to describe concepts of greater complexity.
It is important that you learn the words in your new vocabulary enough to be able to understand sentences that may contain two or more slang words. Unfortunately, you’re unlikely to ever fully understand how to use PHP unless you understand the difficult concepts behind it, and that means learning the technical language.
A simple example would be understanding ‘how to pass a variable as an argument to your function.’
Udemy’s ‘Learn PHP Online’ course covers the concepts of variables, functions and arguments as part of its PHP Fundamentals curriculum, so by the end of the course this sentence should make perfect sense to you. If you’re worried that this might be difficult, consider writing down what each jargon word means when you come across them so you can repeat them when the instructor uses such a sentence later in your PHP education.
The tips in this guide will help you prepare to become a better PHP student and ensure a more efficient learning process if followed correctly.
While most of these tips are aimed at those who are early in their quest to learn PHP, some will prove useful to those who are more advanced in their PHP education.
But anyway, now that you’ve put some research into it, you might have decided to Learn PHP, If so, there is only one thing left to do…
It’s time to learn PHP!
It can be a daunting process, just like anything we choose to learn. But for many, it’s a beautiful journey and there’s a tremendously rewarding feeling at the end of it. Follow the tips in this guide and you’ll be well on your way.
If you have any questions for me, don’t hesitate to ask. Simply leave a comment below and I’ll get back to you as soon as possible!