How to display errors in PHP?

Executing a PHP file can result in an error and there are cases when you don't get any information about the things that went wrong in the process as you could see a blank page or any weird things on the browser. This page explains how to display errors in PHP.

How to display errors in PHP?

These errors are logged in the PHP log file or the server log file, but you can simply make changes to your code to quickly view it on the browser.

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

These variables are normally defined in your php.ini file. The above lines `ini_set()` is basically overriding these configuration options in your code.

The value of display_errors decides if the errors should be displayed to the user or hidden from it.

The above variable does not display the errors which occur during the PHP's startup sequence. To display them, you need to enable display_startup_errors directive.

error_reporting - This is used to set up the errror reporting level. There levels are decided based on the predefined constant used in the parameter.  

E_ERROR Fatal run-time errors
E_WARNING Run-time warnings (non-fatal errors).

The code execution found something that needs to be noticed by the developer. This could result in an error.

E_ALL All errors and warnings

More options can be found at