This article mainly introduces the method of error in the PHP capture, has a certain reference value, now share to everyone, the need for friends can refer to
PHP Catch Error
error_reporting (0);
Set_error_handler (' ErrorHandler ');
Register_shutdown_function (' Fatalerrorhandler ');
/** * @param int $err _no Error code * @param string $err _msg Error message * @param string $err _file Error file * @param int
$err _line Error Line number * @return string */function errorhandler ($err _no = 0, $err _msg = ', $err _file = ', $err _line = 0) { c6/> $log = [' ['. Date (' y-m-d h-i-s '). '] ', ' | ', $err _no, ' | ', $err _msg, ' | ', $err _ File, ' | ', $err _line ]; $log _path = './test.txt '; Error_log (Implode (", $log)." \ r \ n ", 3, $log _path);}
function Fatalerrorhandler () { $e = Error_get_last (); Var_export ($e); Switch ($e [' type ']) {case 1: errorhandler ($e [' type '], $e [' message '], $e [' file '], $e [' line ']); break; }}
Class democlass_1{public function Index () { //A warning error occurred here, departure ErrorHandler echo $undefinedVarible; }}
$demo _1 = new Democlass_1 (); $demo _1->index ();
$demo _2 = new Democlass_2 (); $demo _2->index ();
Output after opening test.txt:
[2018-06-12 05-49-11] | 8 | Undefined variable:undefinedvarible | /users/darry/htdocs/test.php | 57[2018-06-12 05-49-11] | 1 | Uncaught error:class ' democlass_2 ' not found In/users/darry/htdocs/test.php:67stack trace: #0 {main} thrown |/users /darry/htdocs/test.php | 67
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!
Related recommendations:
Nginx SSL Fast bidirectional Authentication configuration (script)
Recursion of PHP Data structure basics
About the use of thinkphp behavior