Bugs Debugging PHP

Rarely do programmes work right the first time. There are a lot of things that could go wrong with your programme and cause the PHP interpreter to show an error message. You can decide where these error messages should go. The messages can be sent to the web browser along with other programme output. They can also be put in the error log of the web server.

Set the display errors configuration directive to On to get error messages to show up in the browser. Set log errors to On to send errors to the web server’s error log. If you want error messages in both places, you can turn both of them on.

PHP has some constants you can use to set the value of error reporting so that only certain kinds of errors are shown: E ALL (for all errors except strict notices), E PARSE (parse errors), E ERROR (fatal errors), E WARNING (warnings), E NOTICE (notices), and E STRICT (strict notices).

When writing your PHP programme, you should use an editor that knows about PHP, like BBEdit or Emacs. One of the cool things about these editors is that they highlight syntax. It gives different parts of your programme a different colour based on what they are. For example, strings are pink, keywords like if and while are blue, comments are grey, and variables are black.

Quote and bracket matching is another feature that helps make sure that your quotes and brackets are in the right places. When you type a closing delimiter like, the editor highlights the matching opening.

When you’re trying to fix a bug in your programme, you need to check the following things.

  • Semicolons Missing: Each PHP statement ends with a semicolon (;). PHP keeps reading an entire statement until it gets to a semicolon. If you leave out the semicolon at the end of a line, PHP will read the statement on the next line.
  • Not Enough Equal Signs: You need two equal signs (==) in a comparison statement to ask if two values are the same. A common mistake is to use only one equal sign.
  • Variable Names That Are Spelt Wrong: If you misspell a variable name, PHP sees it as a new variable. Remember that $test and $Test are not the same thing in PHP.
  • Missing Dollar Signs :  A missing dollar sign in a variable name is hard to spot, but you usually get an error message that tells you where the problem is.
  • Quotes that are hard to understand: You can have too many, too few, or the wrong kind of quotes. So, make sure you have an even number of quotes.
  • Missing Parentheses and curly brackets: Parentheses and curly brackets are missing. There should always be two of each.
  • Array Index: Instead of starting with 1, all the arrays should start with 0.

Also, make sure to handle all errors correctly and send all trace messages to the system log file. This way, if there is a problem, it will be written down in the system log file and you will be able to fix it.

People also search

Leave a Comment

Scroll to Top