是否可以让 PHP 错误看起来更好一些?堆栈跟踪可以在单独的行上输出吗?

发布于 2024-12-09 11:46:05 字数 1109 浏览 1 评论 0原文

现在 PHP 只是在页面上转储如下内容:

致命错误:无法重新声明 Cms\getItemHierarchy()(以前 声明于 /home/cartman/Development/cmsdev/engine_1.0/Cms/Menu.php:62) 在 /home/cartman/Development/cmsdev/engine_1.0/Cms/Menu.php 第 62 行 调用堆栈:0,0001 634424 1. {main}() /home/cartman/Development/cmsdev/public_normal/index.php:0 0,0037 757768 2.Bootstrap::run() /home/cartman/Development/cmsdev/public_normal/index.php:7 0,0037 757768 3. Cms\Front->dispatch() /home/cartman/Development/cmsdev/data_product/bootstrap.php:94 0,0043 781512 4. frontendController->contactusAction() /home/cartman/开发/cmsdev/engine_1.0/Cms/Front.php:367 0,0051 817152 5.plugins\m3nu\api->renderMenu($configName = 'bottom', $activeItem = '联系我') /home/cartman/Development/cmsdev/data_product/controllers/frontendController.php:43 0,0052 825392 6. Cms\Menu->generateMenu() /home/cartman/Development/cmsdev/public_normal/plugins/m3nu/api.php:29 0,0052 825392 7. Cms\Menu->preParseConfig() /home/cartman/Development/cmsdev/engine_1.0/Cms/Menu.php:121

有没有办法使输出看起来更有组织性,至少在单独的行上打印堆栈跟踪?

Right now PHP simply dumps something like this on the page:

Fatal error: Cannot redeclare Cms\getItemHierarchy() (previously
declared in
/home/cartman/Development/cmsdev/engine_1.0/Cms/Menu.php:62) in
/home/cartman/Development/cmsdev/engine_1.0/Cms/Menu.php on line 62
Call Stack: 0,0001 634424 1. {main}()
/home/cartman/Development/cmsdev/public_normal/index.php:0 0,0037
757768 2. Bootstrap::run()
/home/cartman/Development/cmsdev/public_normal/index.php:7 0,0037
757768 3. Cms\Front->dispatch()
/home/cartman/Development/cmsdev/data_production/bootstrap.php:94
0,0043 781512 4. frontendController->contactusAction()
/home/cartman/Development/cmsdev/engine_1.0/Cms/Front.php:367 0,0051
817152 5. plugins\m3nu\api->renderMenu($configName = 'bottom',
$activeItem = 'contactme')
/home/cartman/Development/cmsdev/data_production/controllers/frontendController.php:43
0,0052 825392 6. Cms\Menu->generateMenu()
/home/cartman/Development/cmsdev/public_normal/plugins/m3nu/api.php:29
0,0052 825392 7. Cms\Menu->preParseConfig()
/home/cartman/Development/cmsdev/engine_1.0/Cms/Menu.php:121

Is there a way to make the output look more organized, at least print stack trace on separate lines?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦开始←不甜 2024-12-16 11:46:05

您还可以更新 php.ini 以包含一些 HTML 格式。

html_errors = On
error_prepend_string = "<pre style='color: #333; font-face:monospace; font-size:8pt;'>"
error_append_string = "</pre>"

或者,如果您希望在运行时设置它们,请在脚本顶部包含以下内容

ini_set("html_errors", "1"); 
ini_set("error_prepend_string", "<pre style='color: #333; font-face:monospace; font-size:8pt;'>"); 
ini_set("error_append_string ", "</pre>"); 

You can also update the php.ini to include some formatting HTML.

html_errors = On
error_prepend_string = "<pre style='color: #333; font-face:monospace; font-size:8pt;'>"
error_append_string = "</pre>"

Or if you'd prefer to set them at runtime include the following at the top of your script(s)

ini_set("html_errors", "1"); 
ini_set("error_prepend_string", "<pre style='color: #333; font-face:monospace; font-size:8pt;'>"); 
ini_set("error_append_string ", "</pre>"); 
眼角的笑意。 2024-12-16 11:46:05

这似乎是 XDebug 堆栈跟踪。尝试在 php.ini 中设置 trace_format

xdebug.trace_format = 2 # HTML formatting

This seems to be an XDebug stack trace. Try setting trace_format in php.ini:

xdebug.trace_format = 2 # HTML formatting
葵雨 2024-12-16 11:46:05

如果您从浏览器中查看它们,则可以将其包装在

标记中,这实际上会将换行符显示为换行符。

否则,如果您在 DOM 之外查看,即在控制台或源查看器中,您会发现它们已经“很好”地格式化了

If you are viewing them from a browser, you can wrap it in

<pre></pre>

tags which will essentially present your newline characters as line breaks.

Otherwise, if you are viewing outside of DOM, i.e., in console or source viewer, you will find they are already formatted "nicely"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文