Saturday, March 3, 2012

[PHP] Error Reporting : Turn off Warnings/Errors/Notices

Hi Friends,

Recently I was writing a simple personal site. I had to add some php script as well to communicate with mysql server. For any error, warning, I used to see messages in browser which can be frustrating at times. If you are looking for a way to disable those messages.. here it is.

We are going to use error_reporting($level) function of php. Syntax is:
int error_reporting ([ int $level ] )

Write this in php file where you want.
<?php
// Turn off all error reporting
error_reporting(0);

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting(E_ALL);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

?>

Thats how you do.. Cheers!!!

-Ravi -aka- D'Maverick



2 comments:

  1. Thanks so much Ravi! Implemented that code and it got rid of those annoying messages for me. Did some more research on the error_reporting function and also the "@" operator and came across this page which explains it all quite nicely:


    http://www.programmerinterview.com/index.php/php-questions/how-to-remove-warnings-in-php/

    ReplyDelete
  2. You are welcome buddy.. :)

    Thanks for the link sharing.. :)

    ReplyDelete

Note: Only a member of this blog may post a comment.