Better error reporting for PHP, and prettier too!

Overview

PHP Error | Improve Error Reporting for PHP

THIS IS NO LOBGER MAINTAINED, Please leave me alone.

PHP errors are not good enough for development, it's as simple as that. This aims to solve this.

Better Error Message

When an error strikes, the page is replaced with a full stack trace, syntax highlighting, and all displayed to be readable.

Works with Ajax too!

If the server errors during an ajax request, then the request is paused, and the error is displayed in the browser. You can then click to automatically retry the last request.

ajax server stack trace

This requires no changes to your JavaScript, and works with existing JS libraries such as jQuery.

Do not use on a live site!

To help make development easier, this deliberately makes your code unsafe. External requests are allowed to change your code, it shows more about your site, gives you more info, and makes trivial errors fatal. All of that is awesome if you want to fix bugs in less time, but in production, it is totally unsafe.

seriously, only use this for development!

In case you forget, you can disable this in production using the 'php_error.force_disabled' php.ini option (see below).

Features

  • trivial to use, it's just one file
  • errors displayed in the browser for normal and ajaxy requests
  • ajax requests are paused, allowing you to automatically re-run them
  • makes errors as strict as possible (encourages code quality, and tends to improve performance)
  • code snippets across the whole stack trace
  • provides more information (such as full function signatures)
  • fixes some error messages which are just plain wrong
  • syntax highlighting
  • looks pretty!

Getting Started

  • Download, it's just one file.
  • Place it in your project.
  • import php_error.php
  • call \php_error\reportErrors()
    <?php
        require( 'php_error.php' );
        \php_error\reportErrors();
    ?>

Documentation

Example Setup

API

Options

php.ini settings

Advanced Features

  • customization
  • manually turn it on and off
  • run specific sections without error reporting
  • ignore files allowing you to avoid highlighting code in your stack trace
  • application files; these are prioritized when an error strikes!

Application Aware Stack Trace

Comments
  • WordPress displays errors normal way

    WordPress displays errors normal way

    Maybe I am doing something wrong but the error handling is not affected at all in my WordPress application (v3.4.2). I followed the instructions in documentation and include it to header.php in theme. I also tried to initialize it directly when WordPress loads but with a same result.

    I would like to have all the major errors in plugins and theme handled by your tool which is btw very cool. Thanks for your work on PHP Error anyways, very helpful on other projects too.

    opened by johnnypea 13
  •  Wrong parameters for ErrorException

    Wrong parameters for ErrorException

    Wrong parameters for ErrorException([string $exception [, long $code, [ long $severity, [ string $filename, [ long $lineno [, Exception $previous = NULL]]]]]]) /********** set_error_handler( function( $code, $message, $file, $line, $context ) use ( $self, &$catchSurpressedErrors ) { if ($self->isOn()) { @ini_set('html_errors', false); if (error_reporting() !== 0 || $catchSurpressedErrors) { offending line ----> $ex = new ErrorException($message, $code, $code, $file, $line); if ($self->throwErrors) { throw $ex; } else { $self->reportException($ex); } } } else { return false; } }, $this->defaultErrorReportingOn ); /****** At this point I am not seeing the correct solution, ie code blind. Some help would be good. thanks

    opened by wriver4 7
  • NOTICE is not handled

    NOTICE is not handled

    Even when setting error_reporing_on to E_ALL | E_STRICT, I still see the small default PHP notice rather than PHP-Error's full page dialog.

    \php_error\reportErrors(array(
         'catch_supressed_errors' => true,
         'error_reporting_on' => E_ALL | E_STRICT,
    ));
    
    Notice!
    
    ErrorException [ Notice ]: Use of undefined constant asdf - assumed 'asdf'
    

    Shouldn't E_ALL cover E_NOTICE and E_USER_NOTICE?

    This may be a bug in the script or a bug in the documentation.

    opened by NateRadebaugh 6
  • Support fatal errors

    Support fatal errors

    Please add support for fatal errors - this can be done via register_shutdown_function and error_get_last http://stackoverflow.com/questions/277224/how-do-i-catch-a-php-fatal-error

    Otherwise - great library! Thanks!

    Triggering fatal that is not handled by PHP-Error:

    $a = array(); while(true) $a []= 'fatal';
    
    opened by slava-vishnyakov 5
  • A method to generate file links, akin to xdebug.file_link_format?

    A method to generate file links, akin to xdebug.file_link_format?

    With xdebug, I can define a format for links to the filename/line number of the call stack, for example:

    xdebug.file_link_format="javascript:var d=document,r=d.createElement(\"script\");r.src=\"http://localhost:8091?message=%f:%l\";d.body.appendChild(r);void(null)"
    

    Here, the generated links allow me to click to open the file in question directly in IntelliJ IDEA. Is it possible to preserve the link format, or maybe use the xdebug.file_link_format ini setting to format it that way by yourself?

    enhancement 
    opened by demonkoryu 5
  • No nice html markup nor style, using latest php_error in combination with php 5.4

    No nice html markup nor style, using latest php_error in combination with php 5.4

    Hello.

    I am using the latest version of PHP_Error grabbed from Github today.

    When running the example call_via_native.php it only returns this body:

    Undefined variable: b 
               D:\HostingSpaces\cms\wv.dev02.tactcms.nl\wwwroot\CMS2MVC\public\errortest.php, 6 
            #0 D:\HostingSpaces\cms\wv.dev02.tactcms.nl\wwwroot\CMS2MVC\public\errortest.php(6): php_error\ErrorHandler->php_error\{closure}(8, 'Undefined varia...', 'D:\HostingSpace...', 6, Array)
            #1 [internal function]: {closure}()
            #2 D:\HostingSpaces\cms\wv.dev02.tactcms.nl\wwwroot\CMS2MVC\public\errortest.php(9): call_user_func(Object(Closure))
            #3 {main}
    

    There is no HTML within the response.. Does something needs to be set? or is this normal behavior?

    opened by yolandavdvegt 5
  • Fails on WordPress

    Fails on WordPress

    [02-Jul-2012 15:51:50 UTC] Redefining already defined constructor for class WP_Widget
               C:\wamp\www\wordpress\wp-includes\widgets.php, 93
            #0 C:\wamp\www\wordpress\wp-settings.php(144): php_error\{closure}(2048, 'Redefining alre...', 'C:\wamp\www\wor...', 93, Array)
            #1 C:\wamp\www\wordpress\wp-settings.php(144): require()
            #2 C:\wamp\www\wordpress\wp-config.php(96): require_once('C:\wamp\www\wor...')
            #3 C:\wamp\www\wordpress\wp-load.php(29): require_once('C:\wamp\www\wor...')
            #4 C:\wamp\www\wordpress\wp-admin\admin.php(30): require_once('C:\wamp\www\wor...')
            #5 C:\wamp\www\wordpress\wp-admin\index.php(10): require_once('C:\wamp\www\wor...')
            #6 {main}
    

    Turning on php_error.wordpress = On fixes this issue...Not ideal, though

    opened by Geczy 5
  • Let's appoint another

    Let's appoint another "de facto" maintainer.

    No offense to @JosephLenton, he is the man after all, but I think it's time that someone else steps in and collects all those lingering pull requests. I nominate @panrafal . What do you think?

    opened by demonkoryu 4
  • Need ability to turn off

    Need ability to turn off "magic JS" prepend from within application

    In sending generated csv files to the user to save, I set headers and use readfile. I am ending up with the this "magic JS" prepended to my files. I have tired executing the code through withoutErrors with the same results.

    opened by christianmagill 4
  • private method identifyTypeHTML()

    private method identifyTypeHTML()

    Changing it to public makes everything work again

    [02-Jul-2012 15:46:29 UTC] PHP Fatal error:  Call to private method php_error\ErrorHandler::identifyTypeHTML() from context '' in C:\wamp\php\php_error.php on line 2123
    
    [02-Jul-2012 15:46:29 UTC] PHP Stack trace:
    
    [02-Jul-2012 15:46:29 UTC] PHP   1. php_error\{closure}() C:\wamp\php\php_error.php:0
    
    [02-Jul-2012 15:46:29 UTC] PHP   2. php_error\ErrorHandler->reportException() C:\wamp\php\php_error.php:2274
    
    [02-Jul-2012 15:46:29 UTC] PHP   3. php_error\ErrorHandler->reportError() C:\wamp\php\php_error.php:2048
    
    [02-Jul-2012 15:46:29 UTC] PHP   4. php_error\ErrorHandler->generateDumpHTML() C:\wamp\php\php_error.php:2100
    
    [02-Jul-2012 15:46:29 UTC] PHP   5. php_error\{closure}() C:\wamp\php\php_error.php:2134
    
    [02-Jul-2012 15:46:29 UTC] PHP   6. php_error\{closure}() C:\wamp\php\php_error.php:0
    
    [02-Jul-2012 15:46:29 UTC] PHP   7. php_error\ErrorHandler->__onShutdown() C:\wamp\php\php_error.php:2378
    
    [02-Jul-2012 15:46:29 UTC] PHP   8. php_error\ErrorHandler->reportError() C:\wamp\php\php_error.php:1201
    
    [02-Jul-2012 15:46:29 UTC] PHP   9. php_error\ErrorHandler->generateDumpHTML() C:\wamp\php\php_error.php:2100
    
    [02-Jul-2012 15:46:29 UTC] PHP  10. php_error\{closure}() C:\wamp\php\php_error.php:2134
    
    opened by Geczy 4
  • Syntax error in php_error.php

    Syntax error in php_error.php

    Download php_error from github, added it in ini file and bam:

    Parse error: syntax error, unexpected $end in C:\wamp\php\php_error.php on line 3812

    No clue what's going on here

    opened by Geczy 4
  • added a custom 500 error page

    added a custom 500 error page

    modifying the file shoulbe disabled by default debug option true | false ln 113 if debug is true ? dump off the error log : show a normal html 500 error page

    opened by ibnsultan 0
  • No backtrace?

    No backtrace?

    I was expecting some kind of backtrace like in your examples but I'm only getting the fatal error and where it is. For instance:

    <?php
    
    require_once('php_error.php');
    \php_error\reportErrors();
    
    class Test
    {
        public function A()
        {
            return $this->B();
        }
    
        public function B()
        {
            return $this->C();
        }
    
        public function C()
        {
            return $this->D();
        }
    }
    
    $test = new Test();
    $test->A();
    
    

    I'm getting:

    
    Call to undefined method Test::D()
    39 cgi-bin/scripts/test.php
        }
        /**
         * undocumented function
         *
         * @return void
         */
        public function C()
        {
            return $this->D();
        }
    }
    

    While I'd like to see also the backtrace:

    14 return $this->C();

    9 return $this->B();

    24 $test->A();

    Am I missing anything?

    opened by fcojavierdomenech 0
  • 'Magic JS' right after doctype breaks AngularJS $http promises.

    'Magic JS' right after doctype breaks AngularJS $http promises.

    Hi Joseph,

    You've done some cool work with this module, however after hours of investigation I've found one very important Angular/JavaScript related issue.

    I've found that something inside "magic JS, just ignore this!" script causes break of all AngularJS $http service callbacks (.then, .success etc. which are used in any AJAX call through this service). They're all silenced with either no success or any error. Roughly checking you may be manipulating XMLHttpRequest object in this script in some inappropriate way which may be the cause of this problem. Tested on latest Chrome & Firefox, I haven't checked other browsers.

    best regards, Ireneusz Sawicki

    opened by ireksawicki 0
  • Parse error: syntax error

    Parse error: syntax error

    Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /home/u466736518/public_html/core/init.php on line 25

    guys help please.

    init.php code

    array( 'host' => 'mysql.hostinger.ru', 'username' => 'u466736518_fles', 'password' => '643350np', 'db' => 'u466736518_fles' ), 'remember' => array( 'cookie_name' => 'hash', 'cookie_expiry' => 604800 ), 'sessions' => array( 'session_name' => 'user', 'token_name' => 'token' ) ); spl_autoload_register(function($class) { --------line 25 require_once './classes/' . $class . '.php'; }); require_once './functions/sanitize.php'; if(Cookie::exists(Config::get('remember/cookie_name')) && !Session::exists(Config::get('sessions/session_name'))) { $hash = Cookie::get(Config::get('remember/cookie_name')); $hashCheck = DB::getInstance()->get('users_session', array('hash', '=', $hash)); if($hashCheck->count()) { $user = new User($hashCheck->first()->user_id); $user->login(); } }
    opened by parfenovn 1
  • Add support for nested output buffers

    Add support for nested output buffers

    This uses the ob_get_level command to work out how many output buffers we need to close before we make our own output.

    This enables using PHP-Error in applications such as magento.

    This fixes #76

    opened by bullfrogchampion 0
Owner
Joseph Lenton
Joseph Lenton
Prettier PHP Plugin

Prettier PHP Plugin Intro Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its o

Prettier 1.6k Jan 5, 2023
A super simple, clean and pretty error handler that replace the default error handler of PHP. You need only include this file!

php-custom-error-handler A super simple, clean and pretty error handler that replace the default error handler of PHP. You need just include only this

null 6 Nov 7, 2022
Better Moderation, moderation just done better.

Better Moderation Plugin Commands /ban <player> <reason> <time> - Bans a player from the server. /blacklist <player> - Blacklists a player from the se

Colby Pham 5 Jun 15, 2023
Keep control over the complexity of your methods by checking that they do not have too many arguments.

php arguments detector The ideal number of arguments for a function is zero. ~ Robert C. Martin Keep control over the complexity of your methods by ch

DeGraciaMathieu 13 Dec 26, 2022
Just the stats I want, maybe you want them too

SKCDEV Easy Digital Downloads Stats This plugin adds a new "SKCDEV EDD Stats" report tab to the EDD Reports tabs. Just the stats I want, maybe you wan

Scott Kingsley Clark 3 Sep 8, 2022
Analyzes PHPStan baseline files and creates aggregated error trend-reports

Analyzes phpstan baseline files Analyzes PHPStan baseline files and creates aggregated error trend-reports.

Markus Staab 22 Dec 23, 2022
Parse your humble choice / monthly data and compile a CSV list for better overview

humbleparser Parse your humble choice / monthly data and compile a CSV list for better overview Requirements PHP CLI (>= 7.4)) php-curl Note I have ne

null 1 May 4, 2022
A MCPE server software that backporting new Minecraft: Bedrock Edition to older PocketMine versions with better stability and performance.

CoarseMC is a server software that backports new Minecraft: Bedrock Edition versions to older PocketMine versions with better stability and performance, while retaining as many features from the new PocketMine-MP versions as possible.

null 5 May 21, 2022
Small Library to Serve Images in PHP in a Better Way (Resize, Compress) with Caching Support

A library for serving images and optimizing, changing their sizes, this library uses the caching feature, and in addition, it is very fast and small in size. In addition to these features, this library also optimizes images.

Developix 9 Oct 18, 2022
This script allows to bypass Oracle Cloud Infrastructure 'Out of host capacity' error immediately when additional OCI capacity will appear in your Home Region / Availability domain.

Resolving Oracle Cloud "Out of Capacity" issue and getting free VPS with 4 ARM cores / 24GB of memory Very neat and useful configuration was recently

Alexander Hitrov 323 Jan 6, 2023
Hi everyone! This is our repository for our final project in college. We're sorry if so many bug or error. Thank You

About The Project Hi everyone! This is our repository for our final project in college. We're sorry if so many bug or error. Thank You About Laravel L

Lintang Bima Sakti 3 Dec 9, 2021
Provides the ability to notify developers of error logs via email or SMS.

?? Dev Notify Plugin ?? Requires OctoberCMS 2.0 ✨ What does this plugin do? Provides the ability to notify developers of error logs via email or SMS.

Albright Labs 1 Mar 28, 2022
Error handler with PSR-7 support

Jasny Error Handler Error handler with PSR-7 support. Installation The Jasny Error Handler package is available on packagist. Install it using compose

Arnold Daniels 6 Jun 23, 2022
This Validate Class is for those who are looking for a validator that returns a code for every each error (Laravel/Api)

Validator-Class This Validate Class is for those who are looking for a validator that returns a code for every each error (Laravel/Api) Requirements A

Barbod 3 Jul 18, 2022
Better Version of Cvolton's GMDprivateServer

BetterCvoltonGDPS Better Version of Cvolton's GMDprivateServer Supported version of Geometry Dash: 1.0 - 2.11 (so any version of Geometry Dash works,

foxodever 17 Nov 20, 2022
We go for better world

Nasa-Space-Apps-Challenge-2021 We go for better world Team: Dynamo Warrior Team Member Mazharul Hasan Fozilatunnesa Mestu Paul Nayeem Hossain Belal Ud

Mazharul Hasan 7 Dec 10, 2021
Magento 2 SEO extension will do perfectly for your better SEO.

Magento 2 SEO extension will do perfectly for your better SEO. This is a bundle of outstanding features that are auto-active when you install it from Mageplaza without any code modifications. It is also friendly with your store if you need to insert meta keywords and meta descriptions for your product.

Mageplaza 121 Oct 28, 2022
Magento 2 Blog Extension is a better blog extension for Magento 2 platform. These include all useful features of Wordpress CMS

Magento 2 Blog extension FREE Magento 2 Better Blog by Mageplaza is integrated right into the Magento backend so you can manage your blog and your e-c

Mageplaza 113 Dec 14, 2022
composer plugin for a better frontend setup

node-composer composer plugin for a better frontend setup PHP projects mostly are Web-Applications. Many Web-Applications also need a frontend part wh

Marius Büscher 5 Jul 26, 2022