How to Enable PHP Error Reporting
If you are running into a blank or white page or some other PHP error, but you have no idea what is wrong, you should consider turning on PHP error reporting.
This gives you some indication of where or what the problem is, and it is a good first step to solving any PHP problem.
For syntax errors, you need to enable error display in the php.ini. By default these are turned off because you don’t want a “customer” seeing the error messages.
This saves your time to go through thousands of lines of code looking for an error.
Error_reporting Function
The error_reporting() function specifies which errors are reported.
PHP has many levels of errors, and using this function sets that level for the current script. This function sets the desired level for the duration of your script.
Include the function early in the script, usually immediately after the opening <?php. You have several choices, some of which are illustrated below:
<?php
// Turn off error reporting
error_reporting(0);
// Report runtime errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Report all errors
error_reporting(E_ALL);
// Same as error_reporting(E_ALL);
ini_set(“error_reporting”, E_ALL);
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
?>
Update php.ini file
To see all error reports for all your files, go to your web server and access the php.ini file for your website.You can include the following lines in the file you want to debug:
error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);
The php.ini file is the default configuration file for running applications that use PHP. By placing this option in the php.ini file,
you are requesting error messages for all your PHP scripts.
How to Display Errors
ini_set(‘display_errors’,1); error_reporting(E_ALL);error_reporting(-1);