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
  • PrettyPageHandler: make first frame with comments active on page load

    PrettyPageHandler: make first frame with comments active on page load

    Hello, thank you for sharing this work!

    When using the PrettyPageHandler, I would like the first frame with comments to be active when the page loads, instead of just the first frame. I would be happy to implement this myself. Would you accept a PR to apply such a change?

    If not, would you accept a PR to make the active index a variable passed into the templates? This would at least make it easier to implement in a custom handler extending PrettyPageHandler.

    opened by cogentParadigm 1
  • 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
Cool economy plugin for PM-like servers. API included.

Economy Description Cool and easy to use economy plugin API: 2.0.0 Plugin version: 1.0.0 Default money value on first join: 1000 (can be changed in co

Artem Turov 0 Feb 4, 2022
A cool link aggregator created using Wordpress

A cool link aggregator created using Wordpress

Gabriel Nunes 7 Oct 6, 2022
The ErrorHandler component provides tools to manage errors and ease debugging PHP code

ErrorHandler Component The ErrorHandler component provides tools to manage errors and ease debugging PHP code. Getting Started $ composer require symf

Symfony 2.2k Jan 3, 2023
Task for GrumPHP that adds CSS linting support with stylelint. An easy way to enforce convention and avoid errors in your styles

grumphp-stylelint-task Installation Stylelint is a static analysis tool for styles. A mighty, modern linter that helps you avoid errors and enforce co

null 3 Apr 29, 2021
The Current US Version of PHP-Nuke Evolution Xtreme v3.0.1b-beta often known as Nuke-Evolution Xtreme. This is a hardened version of PHP-Nuke and is secure and safe. We are currently porting Xtreme over to PHP 8.0.3

2021 Nightly Builds Repository PHP-Nuke Evolution Xtreme Developers TheGhost - Ernest Allen Buffington (Lead Developer) SeaBeast08 - Sebastian Scott B

Ernest Buffington 7 Aug 28, 2022
A sampling profiler for PHP written in PHP, which reads information about running PHP VM from outside of the process.

Reli Reli is a sampling profiler (or a VM state inspector) written in PHP. It can read information about running PHP script from outside of the proces

null 272 Dec 22, 2022
PHP Meminfo is a PHP extension that gives you insights on the PHP memory content

MEMINFO PHP Meminfo is a PHP extension that gives you insights on the PHP memory content. Its main goal is to help you understand memory leaks: by loo

Benoit Jacquemont 994 Dec 29, 2022
A sampling profiler for PHP written in PHP, which reads information about running PHP VM from outside of the process.

Reli Reli is a sampling profiler (or a VM state inspector) written in PHP. It can read information about running PHP script from outside of the proces

null 258 Sep 15, 2022
A multithreaded application server for PHP, written in PHP.

appserver.io, a PHP application server This is the main repository for the appserver.io project. What is appserver.io appserver.io is a multithreaded

appserver.io 951 Dec 25, 2022
Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP

Lodash-PHP Lodash-PHP is a port of the Lodash JS library to PHP. It is a set of easy to use utility functions for everyday PHP projects. Lodash-PHP tr

Lodash PHP 474 Dec 31, 2022
A PHP 5.3+ and PHP 7.3 framework for OpenGraph Protocol

Opengraph Test with Atoum cd Opengraph/ curl -s https://getcomposer.org/installer | php php composer.phar install --dev ./vendor/atoum/atoum/bin/atoum

Axel Etcheverry 89 Dec 27, 2022
A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch screens with a resolution of 1024x600 connected to a Raspberry Pi.

EDStatusPanel A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch scr

marcus-s 24 Oct 4, 2022
🐘 A probe program for PHP environment (一款精美的 PHP 探針, 又名X探針、劉海探針)

Simplified Chinese | 简体中文 Traditional Chinese(Taiwan) | 正體中文(臺灣) Traditional Chinese(Hong Kong) | 正體中文(香港) Japanese | 日本語 ?? X Prober This is a probe

Km.Van 1.2k Dec 28, 2022
PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP language

php-text-analysis PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP l

null 464 Dec 28, 2022
PHP generics written in PHP

PHP generics written in PHP Require PHP >= 7.4 Composer (PSR-4 Autoload) Table of contents How it works Quick start Example Features Tests How it work

Anton Sukhachev 173 Dec 30, 2022
PHP exercises from my course at ETEC and some of my own play-around with PHP

etec-php-exercises PHP exercises from my course at ETEC and some of my own play-around with PHP Translations: Português (BR) Projects Project Descript

Luis Felipe Santos do Nascimento 6 May 3, 2022
GitHub action to set up PHP with extensions, php.ini configuration, coverage drivers, and various tools.

GitHub action to set up PHP with extensions, php.ini configuration, coverage drivers, and various tools.

Shivam Mathur 2.4k Jan 6, 2023
php-echarts is a php library for the echarts 5.0.

php-echarts 一款支持Apache EChart5.0+图表的php开发库 优先ThinkPHP5/6的开发及测试。 Apache EChart5.0已经最新发布,在视觉效果、动画效果和大数据展示方面已经远超之前的版本; 故不考虑EChart5.0之前版本的兼容问题;建议直接尝试5.0+

youyiio 5 Aug 15, 2022
Minimalist PHP frame for Core-Library, for Developing PHP application that gives you the full control of your application.

LazyPHP lightweight Pre-Made Frame for Core-library Install Run the below command in your terminal $ composer create-project ryzen/lazyphp my-first-pr

Ry-Zen 7 Aug 21, 2022