The Whoops PHP library is a powerful and user-friendly error handling tool for PHP applications. It provides clear and well-structured error pages, making it easier to debug and fix issues.
✅ Beautiful, interactive error pages
✅ Detailed stack traces with code previews
✅ Easy integration into existing PHP projects
✅ Support for various frameworks (Laravel, Symfony, Slim, etc.)
✅ Customizable with custom handlers and loggers
You can install Whoops using Composer:
composer require filp/whoops
Here's a simple example of how to enable Whoops in your PHP project:
require 'vendor/autoload.php';
use Whoops\Run;
use Whoops\Handler\PrettyPageHandler;
$whoops = new Run();
$whoops->pushHandler(new PrettyPageHandler());
$whoops->register();
// Trigger an error (e.g., calling an undefined variable)
echo $undefinedVariable;
If an error occurs, Whoops will display a clear and visually appealing debug page.
You can extend Whoops by adding custom error handling, for example:
use Whoops\Handler\CallbackHandler;
$whoops->pushHandler(new CallbackHandler(function ($exception, $inspector, $run) {
error_log($exception->getMessage());
}));
This version logs errors to a file instead of displaying them.
Whoops is mainly used in development environments to quickly detect and fix errors. However, in production environments, it should be disabled or replaced with a custom error page.