A Definitive Guide to PHP Bugs Debugging

Hello folks! welcome back to another section of our tutorial on PHP. In this section of our PHP tutorial, we will be studying about PHP Bugs Debugging.

Generally programs hardly works correctly the first time. A lot of things can go wrong in your php code that causes the interpreter to generate an error message. You have a choice about where those error messages go. The messages can be issued along with other program output to the browser. They can also be added in the web server error log.

In order to make error messages display in the web browser, set the display_errors config directives to On. To send errors to the web server error log, set log_errors to On. You can also set them both to On if you want error messages in both places.

PHP programming defines some constants you can use to set the value of error_reporting such that only errors of certain types get reported: E_ALL (for all the errors except strict notices), E_WARNING (warnings), an E_NOTICE (notices) E_PARSE (parse errors), E_ERROR (fatal errors), and lastly E_STRICT (strict notices).

While writing your PHP program, it is a very nice idea to use PHP-aware editors like BBEdit or the Emacs. One of the special traits of these PHP-aware editors is syntax highlighting. It changes the color of the different parts of your program based upon what those parts are. E.g strings are pink in color, keywords such as if and while are blue, comments are grey, and variables are black in color.

Another feature is the quote and bracket matching which helps in making sure that your quotes and brackets are balanced. Whenever you type  a closing delimiter such as }, then the editor highlights the opening { that it matches.

Following below are the points which needs to be verified while debugging your program -

  • Missing Semicolons - Every PHP statements ends with a semicolon (;). PHP does not stop reading a statement till it gets to a semicolon. If you leave out the semicolon at the end of the line, then PHP continues reading the code statement on the following line.
  • Misspelled Variable Name - If you misspelled a variable then PHP understands its a new variable. Remember; To PHP, $test is not the same variable as $Test.
  • Not Enough Equal Signs - When you ask if two values are equal in a comparison statement, you will need two equal signs (==). Using one equal sign is a very common mistake.
  • Troubling Quotes - you can have too many, or too few, or the wrong kinds of quotes. So do check for a balanced number of quotes.
  • Missing dollar Sign - In PHP its very rare to see a missing dollar sign in the name of a variable. However at least it normally results in an error message so that you know where to look for the issue.
  • Array Index - Every arrays in the code should start from 0 instead of 1.
  • A Missing Parentheses and curly brackets - They should always be in pairs.

In addition, handle all the errors properly and direct all the trace messages into the system's log file so that if any issue occurs, it will be logged into the system's log file and you will be able to debug that problem.


Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial guide, we will be discussing about the PHP Date and Time.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.