Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

formatting

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?

like image 464
Stann Avatar asked Oct 13 '11 20:10

Stann


1 Answers

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>"); 
like image 145
Eric Kigathi Avatar answered Nov 02 '22 05:11

Eric Kigathi