PHP Errors

PHP Errors:

PHP throws a different type of errors if something inappropriate happens during the program execution. It could be because of wrong syntax or many other reasons.

By default, PHP handles errors in a simple way. An error message is displayed to the browser with the filename, line number and a description of the error.

Types of PHP Errors

There are four basic types of run-time errors in PHP:

  1. Notices: These are small, non-critical errors that PHP encounters while executing a script. For example, if you are accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all.
  2. Warnings: These are some serious errors – for example, if you try to include a file using include() function and file does not exist at given path. By default, these errors are displayed to the user, but they do not terminate PHP script and rest of the program executes.
  3. Fatal errors: These are critical errors in php. For example, calling a function that does not exist. These errors immediately terminate the php script’s execution. By default these are visible to the users in browser.
  4. Parse Error: These errors also terminate the php script execution immediately. Beginners encounter these errors often, when there is mistake in PHP code/syntax. For example, when we miss semicolon or does not close brackets properly.

Error Reporting:

The error_reporting() function sets the php error reporting. PHP has many levels of errors, using this function you can sets that level of your php script. We can turn on or off different type of errors as per our requirement.

Here are various examples to enable/disable errors in PHP:

Note: It is good to define error_reporting() function at the top of the script. You can use different level of error reporting on different pages by adding above functions in each php script.


Congratulations! Chapter Finished. Do you want to practice more?
Exercises & Assignments
  • No Content Found.