We now have a youtube channel. Subscribe!

A Definitive Guide to PHP Bugs Debugging

PHP Bugs Debugging

Hello folks! welcome back to a new 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 sent along with other program output to the browser. They can also be included in the web server error log.

To make error messages display in the web browser, set the display_error configuration directive to On. To send errors to the server error log, set log_errors to On. You can set them both to on if you want error messages in both places.

PHP 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 errors except strict notices), E_NOTICE(notices), E_PARSE(parse errors), E_STRICT (strict notices), E_ERROR (fetal errors), and E_WARNING (warnings).

While writing your PHP program, it is a nice idea to make use of PHP-aware editors like BBEdit or Emacs. One of the special traits of these editors is syntax highlighting. It changes the color of the different parts of your program based on 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 nice feature is quote and bracket matching which helps in making sure that your quotes and brackets are balanced. When you type a closing delimiter such as }, the editor highlights the opening { that it matches.

The following 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 we 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.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain