Stann
Stann

Reputation: 13948

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

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?

Upvotes: 8

Views: 2939

Answers (3)

Eric Kigathi
Eric Kigathi

Reputation: 2021

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

Upvotes: 12

netcoder
netcoder

Reputation: 67715

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

xdebug.trace_format = 2 # HTML formatting

Upvotes: 5

John Cartwright
John Cartwright

Reputation: 5084

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"

Upvotes: 4

Related Questions