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

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外面用啊?

胡子哥哥
浏览 370回答 1
1回答

一只斗牛犬

可以结合try...catch...去使用 $trace = (new \Exception())->getTrace()[0]; echo '<br>文件号:'.$trace['file'].':'.$trace['line'];
打开App,查看更多内容
随时随地看视频慕课网APP