鍍金池/ 問答/PHP  網(wǎng)絡(luò)安全/ php 如何把 set_error_handler 裡面的錯誤參數(shù)拿到外面用?

php 如何把 set_error_handler 裡面的錯誤參數(shù)拿到外面用?

function myErrorHandler($errno, $errstr, $errfile, $errline)
{
  
  switch ($errno) {
  case E_USER_WARNING:
  $errno = "USER_WARNING";
  break;
  case E_USER_NOTICE:
  $errno = "USER_NOTICE";
  break;
  case E_NOTICE:
  $errno = "NOTICE";
  break;
  case E_WARNING:
  $errno = "WARNING";
  break;
  case E_RECOVERABLE_ERROR:
  $errno = "RECOVERABLE_ERROR";
  break;
  case E_ALL:
  $errno = "ALL";
  break;
  default:
  $errno = "Unknown Error Type";
  break;
  }

  return true;
}

set_error_handler("myErrorHandler");

我要怎麼把 errno errstr errfile errline取出來function外面用???

回答
編輯回答
菊外人

可以結(jié)合try...catch...去使用

 $trace = (new \Exception())->getTrace()[0];
echo '<br>文件號:'.$trace['file'].':'.$trace['line'];
2018年3月11日 02:21