HighND.com

Just another blog?

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);

From php.net:

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);

 

3 thoughts on “How to enable error reporting in PHP without editing php.ini?

  • Backgammon says:

    Well, I do not know if that is going to work for me, but definitely worked for you! Excellent post!

  • warez scene says:

    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 says:

    Heya, Thank you just for that brilliant article! I must bookmark HighND.com. Regards.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


4 × = twenty

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>