1、set_error_hander(callable $error_handler
[, int $error_types
= E_ALL | E_STRICT ])
2、callable set_exception_handler ( callable $exception_handler
)
3、bool header_register_callback ( callable $callback
) //发送内容之前,执行callback
example
1、set_error_hander(callable $error_handler
[, int $error_types
= E_ALL | E_STRICT ])
bool handler ( int $errno , string $errstr [, string $errfile [, int $errline [, array $errcontext ]]] )
set_error_handler(function ($errno,$errstr,$errfile,$errline){
if (!(error_reporting() & $errno)) {
// This error code is not included in error_reporting, so let it fall
// through to the standard PHP error handler
return false;
}
switch ($errno) {
case E_USER_ERROR:
echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
echo " Fatal error on line $errline in file $errfile";
echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
echo "Aborting...<br />\n";
exit(1);
break;
case E_USER_WARNING:
echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
break;
case E_USER_NOTICE:
echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
break;
default:
echo "Unknown error type: [$errno] $errstr<br />\n";
break;
}
/* Don't execute PHP internal error handler */
return true;
});
2、callable set_exception_handler ( callable $exception_handler
)
void handler ( Exception $ex ) //7.0以前
void handler ( Throwable $ex ) //7.0以后
function exception_handler($exception) {
echo "Uncaught exception: " , $exception->getMessage(), "\n";
}
3、bool header_register_callback ( callable $callback
)
header_register_callback(function(){
foreach (headers_list() as $header) {
if (strpos($header, 'X-Powered-By:') !== false) {
header_remove('X-Powered-By');
}
header_remove('X-Test');
}
});