Tags
PHP
Asked 8 years ago
7 Oct 2016
Views 737
jabber

jabber posted

error reporting in php

How can i manage error reporting very well ?
sometime when i want to disable error reporting i use disable_error_reporting (my custom function)


function disable_error_reporting(){
   error_reporting(0);
   ini_set('display_errors', 1);

}


or i use @ before the line of the code to remove error to show to my client ?
so what other option we have so we can manage error reporting well, one function/class to set or unset error reporting.
Mahesh Radadiya

Mahesh Radadiya
answered Nov 30 '-1 00:00

i am sharing here a common function to set error reporting based on the mode :null , min , max , dev , custom



function set_error_reporting($type=0,$custom=''){
	switch ($type)
	{
		default:
 		case 'none':
		case 'null':
		case '0'://no error reporting . its default
			error_reporting(0);
			break;
		case '1':	
		case 'min'://minimum error reporting with error , warning and parse error will be shown
			error_reporting(E_ERROR | E_WARNING | E_PARSE);
			ini_set('display_errors', 1);
			break;
		case '2':
		case 'max'://maximum error reporting:all error will be reported
			error_reporting(E_ALL);
			ini_set('display_errors', 1);
			break;
		case '3':
		case 'dev'://devlopment mode
			error_reporting(-1);
			ini_set('display_errors', 1);
			break;
		case '4':
		case 'custom'://custom mode
			error_reporting($custom);
 			break;


	}
}

Null mode : set_error_reporting(0); or set_error_reporting("null") or set_error_reporting("none") or set_error_reporting(); will disable error reporting .

Min mode : set_error_reporting("min"); will show only Error , Warning and Parse Error. alternative initialization set_error_reporting(1);

Max mode : set_error_reporting("max"); will show all errors , alternative initialization set_error_reporting(2);

Dev Mode : set_error_reporting("dev"); same as max show you all error , alternative initialization set_error_reporting(3);

Custom Mode : set_error_reporting("custom",E_STRICT); in this case you can pass second argument what type error reporting you need , alternative initialization set_error_reporting(4);

hope it help
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

put this code at first line of your code.

ini_set('display_errors',1);
ini_set('error_log','my_file.log');


check my_file.log for errors. Users will not get any Error on screen .but it show Blank page instead when you got FATAL Error.
Post Answer