6 Errors
This chapter covers
- Common errors we encounter in PHP
- Methods of avoiding common runtime and logic errors
- Best practices when writing PHP code.
Knowing and understanding common errors and error messages is beneficial for several reasons. A common understanding of errors will make identifying and fixing problems in your code easier. When you encounter an error in your code, you'll be able to think critically about the problem, identify potential causes, and devise a solution.
Learning about common errors can help you understand the best practices for writing code. We will write more defensive and foolproof code and reduce the number of errors. It also becomes easier for us to explain problems and troubleshoot efficiently.
The more time we spend reading, researching, and practicing, the more knowledgeable we become about what can go wrong when developing. This increases our level of preparedness, allowing us to anticipate and plan for them, making it easier to develop and maintain your code. We become more efficient as we spend less time debugging.
This chapter will review common errors that lead to logic and runtime errors. Essentially, we will be reviewing a few errors that are generally inconspicuous. After reading this chapter, you will better appreciate why knowing and understanding errors is good and how to solve them is better.
Let us start by exploring why displaying pertinent content on the screen is a good idea when an error is encountered.