RSS ? Recent Blog Posts

Blogs ยป Archive for April 4th, 2006

Pretty Blue Screen

by Harry Fuecks

Been playing around with Zend’s framework some more and finally got annoyed enough about how exceptions are displayed to do something about it.

The code at the bottom of this post just needs including somewhere and enables a “pretty” exception handler – it’s not specific to Zend’s framework – to use it just…

<?php
// Require somewhere like index.php
require_once ‘PrettyBlueScreen.php’;

…and away you go.

The idea is not original – it’s PHP port from webpy which used code from Django – imitation and flattery.

What it does, should an uncaught exception occur;

Pretty Colours

Blue Screen

Stack Trace

Stack Trace

Call Arguments

Call Arguments

Source Code Snippets

Source Code

Request Information

Request

Response Headers

Response

At the moment it’s only for PHP 5 exceptions, although it shouldn’t be too hard to modify it to handle normal PHP errors. It probably only works with PHP 5.1+ (have only tested on 5.1.2) but some more tweaking could fix that (at least for PHP 5.0).

Important note: this is only for development – do not place on a public web server – the only information it lacks is your PIN number…

Anyway – the code;

<?php
set_exception_handler(’PrettyBlueScreen’);

function PrettyBlueScreen($e) {
$o = create_function(’$in’,'echo htmlspecialchars($in);’);

 

Sponsored Links

SitePoint Marketplace

Buy and sell Websites, templates, domain names, hosting, graphics and more.

Follow SitePoint on...