visit
ini_set('display_errors', 1);
error_reporting(E_ALL);
The ini_set
function allows you to override the configuration found in your PHP.ini file. The display_errors
option will determine if the errors will be displayed or hidden. It’s important that this error mode be turned off during production.
ini_set('display_errors', 1); //display errors
ini_set('display_errors', 0); //hide errors
Note: Using this won't be able to display parse errors such as missing semicolons or missing curly braces. In this case, you have modifiy your PHP ini configuration
If you can’t see errors after using the ini_set
to display errors, don’t worry you can still do that by going to your PHP.ini file
If you have successfully located the PHP.ini file bravo, all we have to do is to open the file with a text editor and search for display_errors
then we change its value to on.
display_errors = on
Note
: After we have made a change on the php.ini file and saved the file, we must restart our server.
php_flag display_startup_errors on
php_flag display_errors on
This is the same as what you add to the PHP code to show PHP errors. Depending on which files you have access to and how you do deployments and server configurations, you may want to configure display_erros in .htaccess or your PHP.ini file. Many hosting providers will not allow you to modify your PHP.ini
file to enable display_errors.
In the .htaccess file, a custom error log can also be enabled as long as the log folder or the log file is writable by the web server. The log file can be a relative path to where the .htaccess is located, or it can be an absolute path such as /var/www/html/website/public/logs
php_value error_log logs/all_errors.log
error_reporting(E_WARNING);
Hiding and showing a warning is just as simple as adding a single line of code. To show warnings and notices, the parameter for the error reporting function will be E_WARNING | E_NOTICE.
The error_reporting function can also accept E_ERROR and E_PARSE parameters as bitwise operators. To report all errors except for notices, then the parameter is E_ALL & ~E_NOTICE where E_ALL stands for all possible parameters of the error reporting function.\
error_reporting(0);
To remove all errors, warnings, and parse message notices, the parameter that should be passed to the error_reporting function is zero (0). It would be not practical to have this line of code in each of the PHP files. it would be better to turn off report messages in the PHP ini file or in the .htaccess.
error_reporting(E_NOTICE);
error_reporting(E_ALL & ~E_NOTICE);
The error reporting function allows you to filter which errors can be shown. The “~” character means “note” so the parameter ~E_NOTICE means not to show notices. Notice the “&” and “|” characters in between the possible parameters. The “&” character is for “true for all”, while the “|” character represents either one as long as it is true. These two characters have the same meaning in PHP conditions OR and AND.
Also published here.