How to display all errors in PHP?
A PHP application generates several levels of errors and warnings during the runtime of the script. PHP provides four different ways to display these errors and warnings, which are listed below:
There are few lines of code given below, add this to your PHP file to display errors. It is a fastest way to display all the PHP errors and warnings.
The working of above function and directives is as follow:
This function tries to override the configuration that is found in php.ini file.
The display_errors is a directive that determines whether the error will display to the user or remain hidden. It does not handle the errors that occur during PHP's startup sequence.
The display_startup_errors is also a directive, which is used to find the error during the startup sequence of PHP.
The error_reporting is a native function of PHP. It is used to display errors.
The output will be shown a warning to the browser.
Warning: include(jtp.php): failed to open stream: No such file or directory in C:\xampp\htdocs\program\phperror.php on line 6 Warning: include(): Failed opening 'jtp.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\program\phperror.php on line 6
Note: Both these directives display_errors and display_startup_errors would not be able to display the parse errors. Therefore, the PHP.ini configuration must be modified.
Configure PHP.ini to display all errors and warnings
The following changes must be done in php.ini file to display all errors, including parse error, and restart the apache server in xampp.
Set the display_errors directive to "on" in PHP.ini file. It will display all the errors, which cannot be displayed by just calling ini_set() function, such as - syntax and parse errors
PHP program when display_errors is disabled or set to off in php.ini file.
The output will be shown to the browser like the below screenshot when the display_errors directive is disabled.
The output for the above program when display_errors is enabled or set to on in php.ini file, and the server is restarted.
Error Report Level
As we already discussed that PHP produces different levels of errors. So, let's learn what kind of errors is generated in PHP code.