Top Related Projects
Provides tools to manage errors and ease debugging PHP code
The official PHP SDK for Sentry (sentry.io)
💥 Collision is a beautiful error reporting tool for command-line applications
A beautiful error page for Laravel apps
A simple PHP API extension for DateTime.
Quick Overview
Whoops is a PHP error handling framework designed to help developers debug their applications more effectively. It provides a clean and customizable error page interface, making it easier to identify and resolve issues during development.
Pros
- Easy to integrate into existing PHP projects
- Highly customizable error pages and handlers
- Supports various output formats (HTML, JSON, XML, etc.)
- Includes a powerful stack trace viewer
Cons
- May expose sensitive information if not properly configured for production environments
- Can be resource-intensive for high-traffic applications
- Requires PHP 5.5 or later, which may not be suitable for older projects
- Limited built-in support for logging errors to external services
Code Examples
- Basic usage:
use Whoops\Run;
use Whoops\Handler\PrettyPageHandler;
$whoops = new Run;
$whoops->pushHandler(new PrettyPageHandler);
$whoops->register();
This code sets up Whoops with the default PrettyPageHandler for displaying detailed error information.
- Custom error message:
use Whoops\Handler\CallbackHandler;
$whoops->pushHandler(function ($exception, $inspector, $run) {
return 'Whoops! There was an error: ' . $exception->getMessage();
});
This example adds a custom error message using a CallbackHandler.
- JSON output for API responses:
use Whoops\Handler\JsonResponseHandler;
$whoops->pushHandler(new JsonResponseHandler);
This code configures Whoops to return error information in JSON format, which is useful for API responses.
Getting Started
To get started with Whoops, follow these steps:
-
Install Whoops using Composer:
composer require filp/whoops
-
Add the following code to your PHP application's entry point (e.g., index.php):
use Whoops\Run;
use Whoops\Handler\PrettyPageHandler;
$whoops = new Run;
$whoops->pushHandler(new PrettyPageHandler);
$whoops->register();
-
Ensure that display_errors is enabled in your PHP configuration for development environments.
-
Test the integration by intentionally causing an error in your application and observing the Whoops error page.
Competitor Comparisons
Provides tools to manage errors and ease debugging PHP code
Pros of error-handler
- Integrated seamlessly with Symfony framework, providing a cohesive experience
- Offers more advanced error handling features, including custom error pages and logging
- Supports both development and production environments with different error display modes
Cons of error-handler
- Steeper learning curve, especially for developers not familiar with Symfony
- Less visually appealing error pages out of the box compared to Whoops
- Requires more configuration to set up custom error handling
Code Comparison
error-handler:
use Symfony\Component\ErrorHandler\Debug;
Debug::enable();
// Your application code here
Whoops:
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();
// Your application code here
Both libraries aim to improve error handling in PHP applications, but they cater to different needs. error-handler is more suitable for Symfony-based projects or larger applications requiring advanced error handling features. Whoops, on the other hand, is easier to set up and provides visually appealing error pages, making it a popular choice for smaller projects or quick prototyping.
The official PHP SDK for Sentry (sentry.io)
Pros of sentry-php
- Comprehensive error tracking and monitoring solution
- Integrates with Sentry's cloud-based platform for advanced analytics
- Supports distributed tracing and performance monitoring
Cons of sentry-php
- Requires a Sentry account and potentially paid plans for full functionality
- More complex setup and configuration compared to Whoops
- Heavier resource usage due to additional features
Code Comparison
sentry-php:
\Sentry\init(['dsn' => 'https://examplePublicKey@o0.ingest.sentry.io/0']);
try {
thisFunctionWillThrowAnException();
} catch (\Throwable $exception) {
\Sentry\captureException($exception);
}
Whoops:
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();
throw new \Exception("Whoops! Something went wrong.");
Summary
Sentry-php offers a more comprehensive error tracking solution with cloud-based analytics and performance monitoring, but requires a Sentry account and more complex setup. Whoops provides a simpler, standalone error handling solution with an attractive error page, but lacks advanced features like distributed tracing and remote error logging. Choose based on your project's complexity and monitoring needs.
💥 Collision is a beautiful error reporting tool for command-line applications
Pros of Collision
- Tailored for Laravel applications, providing seamless integration
- Offers a more interactive and user-friendly console output
- Includes advanced features like command autocompletion and syntax highlighting
Cons of Collision
- Limited to Laravel ecosystem, less versatile for other PHP projects
- May have a steeper learning curve for developers unfamiliar with Laravel
Code Comparison
Whoops:
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();
Collision:
$handler = new \NunoMaduro\Collision\Provider;
$handler->register();
Summary
Whoops is a more general-purpose error handler for PHP applications, offering flexibility and ease of use across various PHP projects. It provides a clean and informative error page out of the box.
Collision, on the other hand, is specifically designed for Laravel applications. It enhances the console experience with features like syntax highlighting and command autocompletion. While it offers a more polished experience for Laravel developers, it may not be the best choice for non-Laravel PHP projects.
Both libraries aim to improve error handling and debugging, but they cater to different audiences and use cases. The choice between them largely depends on the project's framework and specific requirements.
A beautiful error page for Laravel apps
Pros of Ignition
- Tailored specifically for Laravel, offering deeper integration and Laravel-specific features
- Provides a more comprehensive solution with query and request information, stack frames, and environment details
- Includes a tab-based interface for easier navigation through error details
Cons of Ignition
- Limited to Laravel applications, whereas Whoops is framework-agnostic
- May have a steeper learning curve for developers not familiar with Laravel
- Potentially heavier resource usage due to additional features
Code Comparison
Whoops:
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();
Ignition:
use Facade\Ignition\Ignition;
Ignition::make()
->registerConfigAliases()
->register();
Both libraries aim to provide detailed error reporting, but Ignition is more tightly integrated with Laravel and offers additional features specific to the framework. Whoops, on the other hand, is more versatile and can be used in various PHP projects. The choice between the two depends on the specific needs of the project and the framework being used.
A simple PHP API extension for DateTime.
Pros of Carbon
- Specialized for date and time manipulation, offering extensive functionality for working with dates, times, and timezones
- Provides a fluent, intuitive API for common date/time operations
- Actively maintained with frequent updates and a large community
Cons of Carbon
- Limited to date and time functionality, unlike Whoops' broader error handling scope
- May have a steeper learning curve for developers unfamiliar with date/time libraries
- Larger package size compared to Whoops due to its comprehensive feature set
Code Comparison
Carbon:
use Carbon\Carbon;
$date = Carbon::now();
$futureDate = $date->addDays(7);
echo $futureDate->diffForHumans();
Whoops:
use Whoops\Run;
use Whoops\Handler\PrettyPageHandler;
$whoops = new Run;
$whoops->pushHandler(new PrettyPageHandler);
$whoops->register();
While both libraries serve different purposes, this comparison highlights their distinct focuses. Carbon excels in date and time manipulation, offering a rich set of features for working with temporal data. Whoops, on the other hand, provides robust error handling and debugging capabilities. The choice between them depends on the specific needs of your project: date/time operations or error management.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
whoops
PHP errors for cool kids
whoops is an error handler framework for PHP. Out-of-the-box, it provides a pretty error interface that helps you debug your web projects, but at heart it's a simple yet powerful stacked error handling system.
Features
- Flexible, stack-based error handling
- Stand-alone library with (currently) no required dependencies
- Simple API for dealing with exceptions, trace frames & their data
- Includes a pretty rad error page for your webapp projects
- Includes the ability to open referenced files directly in your editor and IDE
- Includes handlers for different response formats (JSON, XML, SOAP)
- Easy to extend and integrate with existing libraries
- Clean, well-structured & tested code-base
Sponsors
Installing
If you use Laravel 4, Laravel 5.5+ or Mezzio, you already have Whoops. There are also community-provided instructions on how to integrate Whoops into Silex 1, Silex 2, Phalcon, Laravel 3, Laravel 5, CakePHP 3, CakePHP 4, Zend 2, Zend 3, Yii 1, FuelPHP, Slim, Pimple, Laminas, or any framework consuming StackPHP middlewares or PSR-7 middlewares.
If you are not using any of these frameworks, here's a very simple way to install:
-
Use Composer to install Whoops into your project:
composer require filp/whoops
-
Register the pretty handler in your code:
$whoops = new \Whoops\Run; $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler); $whoops->register();
For more options, have a look at the example files in examples/
to get a feel for how things work. Also take a look at the API Documentation and the list of available handlers below.
You may also want to override some system calls Whoops does. To do that, extend Whoops\Util\SystemFacade
, override functions that you want and pass it as the argument to the Run
constructor.
You may also collect the HTML generated to process it yourself:
$whoops = new \Whoops\Run;
$whoops->allowQuit(false);
$whoops->writeToOutput(false);
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$html = $whoops->handleException($e);
Available Handlers
whoops currently ships with the following built-in handlers, available in the Whoops\Handler
namespace:
PrettyPageHandler
- Shows a pretty error page when something goes pants-upPlainTextHandler
- Outputs plain text message for use in CLI applicationsCallbackHandler
- Wraps a closure or other callable as a handler. You do not need to use this handler explicitly, whoops will automatically wrap any closure or callable you pass toWhoops\Run::pushHandler
JsonResponseHandler
- Captures exceptions and returns information on them as a JSON string. Can be used to, for example, play nice with AJAX requests.XmlResponseHandler
- Captures exceptions and returns information on them as a XML string. Can be used to, for example, play nice with AJAX requests.
You can also use pluggable handlers, such as SOAP handler.
Authors
This library was primarily developed by Filipe Dobreira, and is currently maintained by Denis Sokolov. A lot of awesome fixes and enhancements were also sent in by various contributors. Special thanks to Graham Campbell and Markus Staab for continuous participation.
Top Related Projects
Provides tools to manage errors and ease debugging PHP code
The official PHP SDK for Sentry (sentry.io)
💥 Collision is a beautiful error reporting tool for command-line applications
A beautiful error page for Laravel apps
A simple PHP API extension for DateTime.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot