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

阅读 2k
1 个回答

可以结合try...catch...去使用

 $trace = (new \Exception())->getTrace()[0];
echo '<br>文件号:'.$trace['file'].':'.$trace['line'];
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题