开发者

Is it possible to make PHP errors look nicer? Can Stack trace output on separate lines?

开发者 https://www.devze.com 2023-04-13 09:38 出处:网络
Right now PHP simply dumps something like this on the page: Fatal error: Cannot redeclare Cms\\getItemHierarchy() (previously

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->dis开发者_Go百科patch() /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?


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>"); 


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

xdebug.trace_format = 2 # HTML formatting


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"

0

精彩评论

暂无评论...
验证码 换一张
取 消