Home > Article > Backend Development > PHP error reporting enables detailed implementation_PHP tutorial
php tutorial error reporting enabled detailed implementation
Definition and usage
error_reporting() sets the error reporting level of php and returns the current level.
Grammar
error_reporting(report_level) If the parameter level is not specified, the current error level will be returned. The following items are possible values of level
*/
//Close all error reports
error_reporting(0);
//Only report running errors
error_reporting(e_error|e_warning|e_parse);
//Report e_notice
error_reporting(e_error|e_warning|e_parse|e_notice);
//Report all running errors except e_notice
//This is the default value of php.ini
error_reporting(e_all ^ e_notice);
//Report all php errors
error_reporting(e_all);
//Same effect as error_reporting(e_all), this setting will also report all php errors
ini_set('error_reporting', e_all);
/*
Value Constant Description
1 e_error fatal run-time errors. errors that can not be recovered from. execution of the script is halted
2 e_warning non-fatal run-time errors. execution of the script is not halted
4 e_parse compile-time parse errors. parse errors should only be generated by the parser
8 e_notice run-time notices. the script found something that might be an error, but could also happen when running a script normally
16 e_core_error fatal errors at php startup. this is like an e_error in the php core
32 e_core_warning non-fatal errors at php startup. this is like an e_warning in the php core
64 e_compile_error fatal compile-time errors. this is like an e_error generated by the zend scripting engine
128 e_compile_warning non-fatal compile-time errors. this is like an e_warning generated by the zend scripting engine
256 e_user_error fatal user-generated error. this is like an e_error set by the programmer using the php function trigger_error()
512 e_user_warning non-fatal user-generated warning. this is like an e_warning set by the programmer using the php function trigger_error()
1024 e_user_notice user-generated notice. this is like an e_notice set by the programmer using the php function trigger_error()
2048 e_strict run-time notices. php suggest changes to your code to help interoperability and compatibility of the code
4096 e_recoverable_error catchable fatal error. this is like an e_error but can be caught by a user defined handle (see also set_error_handler())
8191 e_all all errors and warnings, except level e_strict (e_strict will be part of e_all as of php 6.0)
*/
function unserialize_handler($errno,$errstr) //Custom function
{
echo "invalid serialized value.n"; //Output the specified content
}
$serialized='foo'; //Define string
set_error_handler('unserialize_handler'); //Set user-defined error message function
$original=unserialize($serialized); //Create php value from stored representation
restore_error_handler(); //Restore error information pointer