Lesson 5
Debugging Code
From Grace Hopper and her moth in the 1940s to the present day, programmers have been debugging to locate errors. No one writes perfect code the first time, and the better you are at finding your errors, the less frustrated you will be and the better your code will be.
Your first line of defense is using a good editor that validates syntax for you. That catches many possible errors.
In this lesson you learn techniques for locating problems and identifying common issues. You are also introduced to a debugging program you can use to facilitate your debugging.
Troubleshooting Techniques
In this section you learn when and how to display PHP errors in order to get automatic feedback on PHP problems. You also learn what many of the common problems are and how to avoid them. Finally, you are introduced to various ways to see what is happening inside your program as it processes.
Display Errors while Developing
You want errors to be displayed for you while you are developing your code. To do this, make sure that display_errors is on in your php.ini file. You can check this by running phpinfo(). If you are using XAMPP, display_errors is on by default because it is set up for development, not production. This is the code for running phpinfo():
<?php phpinfo();
In the earlier lessons, I included the ending PHP tag of ?> to make it easier and clearer. However, ...