如何告诉 PHP 将异常转储为原始文本而不是 HTML?

2021-12-26 00:00:00 error-handling php

当我在 PHP 中开发我的 REST API 时,我正在使用 application/json 输出,所以当我在浏览器中测试时出现错误时,它们看起来像这样:

When I'm developing my REST API in PHP I'm working with application/json output, so when I get errors while testing in the browser they look like this:

<b>Fatal error</b>: Uncaught exception 'Exception' with message 'PDO caught an error:
array(3) {
  [0]=&gt;
  string(5) &quot;42000&quot;
  [1]=&gt;
  int(1065)
  [2]=&gt;
  string(15) &quot;Query was empty&quot;
}

当我得到大量的堆栈跟踪和其他东西时,情况会变得更糟.那么有没有我可以设置的标志告诉 PHP 我希望我的错误不转义并以原始文本形式显示?

And it gets worse when I get large stack traces and stuff. So is there a flag I can set telling PHP that I want my errors unescaped and in raw text?

推荐答案

这是一个 php.ini 设置,名为 html_errors.

It is a php.ini setting called html_errors.

相关文章