How to enable error reporting in PHP without editing php.ini?
If your website is on a shared hosting and can’t edit your php configuration, or you just want to do a quick debugging for your php script on a production server, you can use the error_reporting function in php:
error_reporting(E_ALL);
int error_reporting ([ int $level ] )
The error_reporting() function sets the error_reporting directive at runtime. PHP has many levels of errors, using this function sets that level for the duration (runtime) of your script. If the optional level is not set, error_reporting() will just return the current error reporting level.
In order to use this function, just put it on the top of your script while specifying the error reporting level:
Turn on all error reporting:
error_reporting(E_ALL);
// OR
error_reporting(-1);
// OR
ini_set('error_reporting', E_ALL);
Turn off all error reporting:
error_reporting(0);
Turn on specific error reporting levels:
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE | E_STRICT | E_DEPRECATED); // Report all errors except E_NOTICE: error_reporting(E_ALL ^ E_NOTICE);
Now if display_errors is turned off in php configuration file, errors will not be displayed on the page even if you’re using error_reporting method , so you need to enable display_errors first with ini_set:
ini_set('display_errors','On');
error_reporting(E_ALL);
Backgammon 10:46 am on October 10, 2011 Permalink |
Well, I do not know if that is going to work for me, but definitely worked for you! Excellent post!
warez scene 8:47 pm on October 18, 2011 Permalink |
This kind of web site post listing features a huge amount of superb info. It’s exciting to look for a index that might draw in countless persons. Make sure you always keep writing, I am excited for the next document.
meg43tr44gi joe 1:51 am on November 5, 2011 Permalink |
Heya, Thank you just for that brilliant article! I must bookmark HighND.com. Regards.