There may be a possibility that your code will not run perfectly for the first time. You may encounter many errors or may make some coding mistakes. It is important that you know how to debug those errors. The task of debugging will be easier if you get the error message stating what is wrong in your code or what part of the code is the source of that error. It is your choice how you want that error message to be generated.
If you want that the error message will get displayed at the web browser then you need to set display_errors directive to on from the configuration file. But if you want to send the errors to the webserver error log then you have to set log_errors to on. But if you want both the possibility then you can set both directives to on. This will make your debugging process easier to check where the code is breaking.
If you want to display some particular type of errors or want to report some specific programming errors then you can set the value of error_reporting .
Also, you can use PHP interactive editors that keep track of the brackets, parenthesis if they are balanced and highlight the code if something is wrong or missing. Below are some points that may cause your program to break. These are maybe small points but very hard to debug.
- Missing semicolons - as we know a statement ends with a semicolon, in case if we miss that the parser will not be able to find the end of the statement and throw an error.
- Not enough equal signs - you should be aware of where to use which equal sign. If you use == in place of = or vice versa the meaning of the code will change and the parser will not get the code correct.
- Misspelled variable names- these are very common mistakes users can make, if you misspelled the variable name that is different from the defined variable name then the parser will not recognize the variable and throw an error.
- Missing dollar sign - dollar sign will define the variable if we miss that the parser will not find the defining variable part and throw an error.
- Troubling quotes- if you miss the start or end quote either single of double the parser will not evaluate the special character or the string and provide you with a different result.
- Missing brackets or parenthesis- brackets and parenthesis should be paired else parser will not parse the code block correctly.
- Array index- the index will always start from zero that maybe the common error made.
People are also reading: