PHP errors for cool kids

Overview

whoops

PHP errors for cool kids

Total Downloads Latest Version Build Status on newer versions Build Status on older versions Scrutinizer Quality Score Code Coverage


Whoops!

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

Blackfire.io

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:

  1. Use Composer to install Whoops into your project:

    composer require filp/whoops
  2. 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-up
  • PlainTextHandler - Outputs plain text message for use in CLI applications
  • CallbackHandler - 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 to Whoops\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.

This software includes Prettify, licensed under Apache License 2.0. It is bundled only as a performance optimization.

Comments
  • Refresh PrettyPageHandler default style

    Refresh PrettyPageHandler default style

    WORK IN PROGRESS - Not ready to merge just yet!

    Scroll to the comments to see the latest versions of the design

    This PR makes a series of changes to default stylesheet for PrettyPageHandler shipped with whoops. The goal is to refresh/modernize it a bit, have it fit larger displays better, and possibly (not yet implemented) add basic mobile support.

    Here's how it looks right now:

    screen shot 2015-06-06 at 5 29 19 pm

    NOTE: While it does seem like a lot of wasted space in some parts, the goal was to improve readability, and that space will collapse on smaller displays, using media queries.

    @denis-sokolov @GrahamCampbell Would love your input - I haven't used whoops in a while, so it'd be good to see if you guys like the direction and think I'm hitting the right targets.

    Cheers!

    opened by filp 46
  • PHP7 and EngineException handling

    PHP7 and EngineException handling

    PHP7 introduces a few new classes related to Exception (RFC). BaseException is created as a parent of Exception, and EngineException is created as a child of BaseException. As a result, the exception handler may receive objects that do not match Exception (EngineException is not an instance of Exception).

    If we were to aim for PHP 7 compatibility only, I'd suggest changing all typehints in Whoops to BaseException, to allow for both Exceptions and EngineExceptions to be passed throughout.

    If we were to aim for PHP 5 and PHP 7 compatibility, as suggested by @LawnGnome, we would need to get rid of the type hint in the exception handler (Run::handleException). We would also need to remove all other typehints for Exception, as they would also need to handle both Exception and EngineException.

    I'm opening this pull request to start discussion, I don't intend for the changes within to be merged without further refinement (still working on a unit test to test catching EngineException).

    opened by adduc 42
  • Uncaught Whoops\Exception\ErrorException: Undefined index: _SERVER

    Uncaught Whoops\Exception\ErrorException: Undefined index: _SERVER

    Anytime my application throws an error (undefined variable or function, on exceptions etc), Whoops PrettyPageHandler shows me a pretty page (like it should) but the error is always the same. It's in the PrettyPageHandler itself.

    Uncaught Whoops\Exception\ErrorException: Undefined index: _SERVER in /var/.../vendor/filp/whoops/src/Whoops/Handler/PrettyPageHandler.php:666 Stack trace: #0 /var/.../vendor/filp/whoops/src/Whoops/Handler/PrettyPageHandler.php(666): Whoops\Run->handleError(8, 'Undefined index...', '/var/www/enstar...', 666, Array) #1 /var/.../vendor/filp/whoops/src/Whoops/Handler/PrettyPageHandler.php(242): Whoops\Handler\PrettyPageHandler->masked('_SERVER') #2

    The error occurs on row 666 (of course :)) in the PrettyPageHandler class:

        private function masked($superGlobalName) {
            $blacklisted = $this->blacklist[$superGlobalName];
            $values = $GLOBALS[$superGlobalName];     <--- /// Row 666, where it breaks
     
            foreach($blacklisted as $key) {
                if (isset($values[$key])) {
                    $values[$key] = str_repeat('*', strlen($values[$key]));
                }
            }
            return $values;
        }
    

    This error happens in both version 2.1.6 and 2.1.7. It looks like the new blacklist feature was added in 2.1.6 and is the root of the problem.

    I'm running PHP 7.1.1 on Ubuntu

    opened by magnus-eriksson 28
  • Offline jQuery / Zepto

    Offline jQuery / Zepto

    Fixes #93.

    This PR bundles ZeptoJS (a smaller, less backwards-compatible version of jQuery) inline, so that the stack works offline, too. Much easier to do than writing all of this in pure JavaScript (yuck).

    While I was at it, I also fixed (I hope?) the scroll-to-top feature, that was trying to use a string value and only not taking padding etc. into account.

    The syntax highlighter will not work offline, but that isn't a crucial feature, so I don't care.

    opened by franzliedke 26
  • Link to Google / StackOverflow

    Link to Google / StackOverflow

    I just spent about 25 minutes working out where to put some code for a PR and ended up doing it on an old version. So, to save me trying to work it out (its 12:45am already), would you consider doing this for me?

                <?php /* Link to help resources */ ?>
                <div class="data-table-container" id="handlers">
                  <label>Help</label>
                  <ul>
                    <li><a href="http://google.com/search?q=<?php echo urlencode(implode('\\', $v->name).' '.$v->message) ?>">Google</a></li>
                    <li><a href="http://stackoverflow.com/search?q=<?php echo urlencode(implode('\\', $v->name).' '.$v->message) ?>">Stack Overflow</a></li>
                  </ul>
                </div>
    

    The general idea is to shove some links in to various search pages, to try and limit how many people copy and paste error messages directly into forums asking for help. If there is a "Help" section then people might start using the internet to answer their questions, and the whole world gets that little bit more bearable.

    opened by philsturgeon 25
  • Hide Certain PHP files or code segments with keywords.

    Hide Certain PHP files or code segments with keywords.

    I started using Whoops! and noticed pretty quickly that the stack traces went right back to my bootstrap page. On the bootstrap page, just slightly above the function call was the mysql password......... Ok I think you can see how this could go. My suggestion would be to blank out lines that have the keyword "pass" or "password" .. Just as a sanity check. Maybe have a keyword that could be in code comments that would blank out the code display altogether. /* WHOOPSBLOCK */ Also have the ability to blank out or omit entire php files from the the stack trace.

    Now you may already have this functionality... Problem is, I couldn't find it in the README.... Thanks!

    opened by canadiannomad 25
  • BC Break in 2.4.0

    BC Break in 2.4.0

    I believe version 2.4.0 contains BC Break (because of https://github.com/filp/whoops/pull/630) in method:

    https://github.com/filp/whoops/blob/cde50e6720a39fdacb240159d3eea6865d51fd96/src/Whoops/Run.php#L130-L133

    Because internal storage has been changed from stack to queue (reversed order) this method return now reversed order of handler than in version prior to 2.4.0.

    Code to reproduce:

    $run->pushHandler($handler1);
    $run->pushHandler($handler2);
    
    assertSame([$handler1, $handler2], $run->getHanlders());
    

    Works on <2.4.0 and fails on 2.4.0+.

    /cc @tflori

    opened by michalbundyra 23
  • PHP 5.5 minimum requirement?

    PHP 5.5 minimum requirement?

    Is there a real reason why you bumped minimum PHP requirement to 5.5.9 instead of 5.4.0?

    I'm asking this because of I have a project where I'm using whoops and I need to support everything between 5.4 and 7.0. I can eventually raise the PHP minimum, but not without prior notice to the users.

    opened by mahagr 23
  • added ZeroClipboard integration

    added ZeroClipboard integration

    this pr adds integration with zero clipboard[1].

    clicking the button copies the exception and its backtrace into the clipboard to ease e.g. creation of bugtracking tickets etc.

    clip

    clicking the button copies the following plain text into the clipboard:

    Exception thrown with message "wah"
    
    Stacktrace:
    #4 Exception in XXXXX/app/www/controllers/IndexController.php:12
    #3 IndexController:index in XXX/lib/ActionController.php:778
    #2 ActionController:invokeAction in XXX/lib/ActionController.php:290
    #1 ActionController:render in XXXCore.php:65
    #0 include_once in XXX/public/www/index.php:29
    

    Since this feature requires a external ZeroClipboard.swf file, I adjusted the path to load it from the cloudfare CDN. The "Copy to Clipboard" button only appears when the external resource could be loaded properly.

    [1] https://github.com/zeroclipboard/zeroclipboard

    opened by staabm 22
  • Dump frame arguments below the source code

    Dump frame arguments below the source code

    This builds on top of #337, but dumps the arguments below the source code (similar to #384).

    Collapsed by default: http://imgur.com/9augmq7 Expand second argument: http://imgur.com/oXfrSfa Expand first and second argument: http://imgur.com/JJQ1oF0 No arguments: http://imgur.com/uWVch0e

    opened by jonasdt 20
  • Remove the final restriction on Whoops\Run

    Remove the final restriction on Whoops\Run

    Allows other libraries, frameworks and projects to mock Whoops\Run by removing its final restriction.

    If extending the class is really not recommended, I'd favor a big comment on the README instead of the final keyword.

    opened by guiwoda 20
  • Adding an additional member variable and getter to PrettyPageHandler

    Adding an additional member variable and getter to PrettyPageHandler

    I would like to propose an addition to the PrettyPageHandler. I have been testing serializing and unserializing errors produced by our codebase in order to easily see what's going on when an issue occurs during one of our cron jobs.

    the main flow of this involves serializing and unserializing the tables and then feeding them back into a prettypagehandler and throwing the exception. Right now, i am able to access the user added data tables, but not the standard base tables, as they are created in the handle() method on 183 in PrettyPageHandler.php.

    I would like to propose adding a member variable, '$allTables' which would be set on ln 285.

    $this->all_tables = $vars["tables"] = array_merge($extraTables, $vars["tables"]);

    by then adding a getAllTables() method, one could easily grab all of the tables to recreate the page

    image

    opened by Baylie21 0
  • Occasional errors with zlib.output_compression = On

    Occasional errors with zlib.output_compression = On

    Hello, occasionally I experience this error when I should not be seeing any whoops-related pages.

    Uncaught Whoops\Exception\ErrorException: ob_end_clean(): failed to discard buffer of zlib output compression (1)

    I've identified the issue is caused by Run.php line 396:

    while ($this->system->getOutputBufferLevel() > 0) {
        $this->system->endOutputBuffering();
    }
    

    I am also submitting a PR with a very simple fix

    opened by kexxt 1
  • Running php from cli, Whoop does not show the file, where first output or headers sent.

    Running php from cli, Whoop does not show the file, where first output or headers sent.

    Reproduce:

    Tested PHP version: 7.2.19, 7.3.6, Whoops version: 2.3.1

    I recently missed "space" into some configuration file. With Whoops turned off, php output shows:

    php -r "include 'index.php';"
    PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/www/public_html/config/dev/database.php:1)
    

    But with Whoops enabled, I have no idea, which file to blame:

    PHP Fatal error:  Uncaught Whoops\Exception\ErrorException: session_set_save_handler(): Cannot change save handler when headers already sent in /home/www/public_html/system/library/session.php:19
    Stack trace:
    #0 [internal function]: Whoops\Run->handleError(2, 'session_set_sav...', '/home/www/publi...', 19, Array)
    #1 /home/www/public_html/system/library/session.php(19): session_set_save_handler(Object(Session\Native))
    #2 /home/www/public_html/system/framework.php(85): Session->__construct()
    #3 /home/www/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(764): {closure}(Object(Registry), Array)
    #4 /home/www/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(646): Illuminate\Container\Container->build(Object(Closure))
    #5 /home/www/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(601): Illuminate\Container\Container->resolve('session', Array)
    #6 /home/www/publi in /home/www/public_html/system/library/session.php on line 19
    Whoops\Exception\ErrorException: Uncaught Whoops\Exception\ErrorException: session_set_save_handler(): Cannot change save handler when headers already sent in /home/www/public_html/system/library/session.php:19
    Stack trace:
    #0 [internal function]: Whoops\Run->handleError(2, 'session_set_sav...', '/home/www/publi...', 19, Array)
    #1 /home/www/public_html/system/library/session.php(19): session_set_save_handler(Object(Session\Native))
    #2 /home/www/public_html/system/framework.php(85): Session->__construct()
    #3 /home/www/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(764): {closure}(Object(Registry), Array)
    #4 /home/www/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(646): Illuminate\Container\Container->build(Object(Closure))
    #5 /home/www/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(601): Illuminate\Container\Container->resolve('session', Array)
    #6 /home/www/publi in file /home/www/public_html/system/library/session.php on line 19
    Stack trace:
      1. Whoops\Exception\ErrorException->() /home/www/public_html/system/library/session.php:19
    

    Is there something to be done?

    opened by arnisjuraga 6
  • drop HHVM and PHP5.x support

    drop HHVM and PHP5.x support

    HHVM is used nearly anywhere and since php7 is a thing also doesnt has a real use-case anymore.

    it was a great project to boost zend-php though.

    we should drop hhvm and php5.x support and cleanup the code-base from hhvm workarounds (and drop hhvm ci).

    do you guys agree? If so, I can provide a PR.

    opened by staabm 16
Handle PHP errors, dump variables, execute PHP code remotely in Google Chrome

PHP Console server library PHP Console allows you to handle PHP errors & exceptions, dump variables, execute PHP code remotely and many other things u

Sergey 1.4k Oct 31, 2022
PHP APM (Alternative PHP Monitor)

APM (Alternative PHP Monitor) APM (Alternative PHP Monitor) is a monitoring extension enabling native Application Performance Management (APM) for PHP

Patrick Allaert 309 Sep 23, 2022
Zipkin PHP is the official PHP Tracer implementation for Zipkin

Zipkin PHP is the official PHP Tracer implementation for Zipkin, supported by the OpenZipkin community. Installation composer require openz

Open Zipkin 250 Nov 12, 2022
Debug bar for PHP

PHP Debug Bar Displays a debug bar in the browser with information from php. No more var_dump() in your code! Features: Generic debug bar Easy to inte

Maxime Bouroumeau-Fuseau 4k Nov 30, 2022
Xdebug — Step Debugger and Debugging Aid for PHP

Xdebug Xdebug is a debugging tool for PHP. It provides step-debugging and a whole range of development aids, such as stack traces, a code profiler, fe

Xdebug 2.7k Nov 28, 2022
Kint - a powerful and modern PHP debugging tool.

Kint - debugging helper for PHP developers What am I looking at? At first glance Kint is just a pretty replacement for var_dump(), print_r() and debug

null 2.7k Nov 22, 2022
PHP Benchmarking framework

PHPBench is a benchmark runner for PHP analogous to PHPUnit but for performance rather than correctness. Features include: Revolutions: Repeat your co

PHPBench 1.7k Nov 22, 2022
The Interactive PHP Debugger

The interactive PHP debugger Implemented as a SAPI module, phpdbg can exert complete control over the environment without impacting the functionality

Joe Watkins 841 Oct 9, 2022
Dontbug is a reverse debugger for PHP

Dontbug Debugger Dontbug is a reverse debugger (aka time travel debugger) for PHP. It allows you to record the execution of PHP scripts (in command li

Sidharth Kshatriya 710 Nov 23, 2022
PHP Debug Console

PHP Console A web console to try your PHP code into Creating a test file or using php's interactive mode can be a bit cumbersome to try random php sni

Jordi Boggiano 523 Nov 7, 2022
Php Debugger to run in terminal to debug your code easily.

What is Dephpugger? Dephpugger (read depugger) is an open source lib to make a debug in php direct in terminal, without necessary configure an IDE. Th

Renato Cassino 191 Oct 20, 2022
PCOV - CodeCoverage compatible driver for PHP

PCOV A self contained CodeCoverage compatible driver for PHP Requirements and Installation See INSTALL.md API /** * Shall start recording coverage in

Joe Watkins 607 Nov 24, 2022
Low-overhead sampling profiler for PHP 7+

phpspy phpspy is a low-overhead sampling profiler for PHP. For now, it works with Linux 3.2+ x86_64 non-ZTS PHP 7.0+ with CLI, Apache, and FPM SAPIs.

Adam 1.3k Nov 27, 2022
The VarDumper component provides mechanisms for walking through any arbitrary PHP variable. It provides a better dump() function that you can use instead of var_dump().

VarDumper Component The VarDumper component provides mechanisms for walking through any arbitrary PHP variable. It provides a better dump() function t

Symfony 7.1k Nov 22, 2022
Clockwork - php dev tools in your browser - server-side component

Clockwork is a development tool for PHP available right in your browser. Clockwork gives you an insight into your application runtime - including requ

its 4.7k Nov 24, 2022
Laravel Debugbar (Integrates PHP Debug Bar)

Laravel Debugbar This is a package to integrate PHP Debug Bar with Laravel. It includes a ServiceProvider to register the debugbar and attach it to th

Barry vd. Heuvel 14.6k Nov 25, 2022
This package connects a Laravel Octance application with Tideways for PHP Monitoring, Profiling and Exception Tracking.

Tideways Middleware for Laravel Octane This package connects a Laravel Octance application with Tideways for PHP Monitoring, Profiling and Exception T

Tideways 7 Jan 6, 2022
A tool to profile mysql queries in php env.

MysqlQueryProfiler This tool helps you to quickly profile a mysql query in a PHP 7.4+ environnement. You can also compare 2 queries. This image shows

null 8 Jul 30, 2021
Datadog Tracing PHP Client

DD Trace PHP PHP Tracer Getting Started The Datadog PHP Tracer (ddtrace) brings APM and distributed tracing to PHP. Installing the extension Visit the

Datadog, Inc. 302 Nov 26, 2022