Formatting PHP Errors


I have built a very small PHP framework as a learning experience, and would like to be able to display the PHP errors in a more readable way, instead of the single line output that is the norm. For example:

Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5-6' for key 'PRIMARY' in C:\xampp\htdocs\food\app\core\Database.php:74 Stack trace: #0 C:\xampp\htdocs\food\app\core\Database.php(74): PDOStatement->execute() #1 C:\xampp\htdocs\food\app\models\Recipe_model.php(376): Database->execute() #2 C:\xampp\htdocs\food\app\controllers\Recipes.php(206): Recipe_model->edit_recipe_categories(Array) #3 C:\xampp\htdocs\food\app\core\App.php(54): Recipes->edit('5') #4 C:\xampp\htdocs\food\public\index.php(5): App->__construct() #5 {main} thrown in C:\xampp\htdocs\food\app\core\Database.php on line 74"

I'd like to split it into separate lines for each part of the trace back. Is there a simple way of doing this?

I took a look at CodeIgniter's code because I like the way they display the errors so that they are easy to read, but the code is very long.


You can make custom exception handler with set_exception_handler.

Examine Exception class to see all info you can get from exception.

Or wrap code pice by pice with try...catch and handle exception in catch block (not recomended, too much code)


How about using something like Xdebug?


I installed XDebug, and that certainly helps. The errors are definitely more readable. I just have to figure out how to style the tables so that the colours are easier on the eyes.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.