Giter Site home page Giter Site logo

php-error's Introduction

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

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

php-error's People

Contributors

alexbilbie avatar geczy avatar josephlenton avatar mrsimonbennett avatar pepamartinec avatar rjkip avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-error's Issues

Parse error not getting processed

I've set it up with the default settings on a test file, and made a simple error ( i typed "blah(;" with no quotes. and it still gives the standard PHP error:
Parse error: syntax error, unexpected ';', expecting ')' in <My_Path>/test.php on line 9

how ever, if i type a function that doesn't exist such as "blah();" then php_error will work corectly. whats going on?

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

DocumentRoot or project root?

Error page appears to show {servername} | {docroot}. Would prefer it show project path;

1229 | $this->applicationRoot = ErrorHandler::optionsPop( $options, 'application_root' , dirname($_SERVER['SCRIPT_FILENAME']) );

Bonus:

Condition on [2399] should surely be session_id() == '', not !==

Use of undefined constant DEBUG_BACKTRACE_IGNORE_ARGS

I followed your simple example with:

require('library/php_error/php_error.php');
\php_error\reportErrors();

right on top of my bootstrap-file in my project. I then just ran reloaded the start page of my project (which doesn't produce an error so far) to check and got a notice message saying:

Use of undefined constant DEBUG_BACKTRACE_IGNORE_ARGS - assumed 'DEBUG_BACKTRACE_IGNORE_ARGS' in     ../php_error.php on line 2460

I run PHP 5.3.3.

PHP Error clashes with ob_gzhandler

I have a PHP file starting with

ob_start('ob_gzhandler');

Placing errors below this line leads to garbage output, i.e., gzipped content without the Content-Encoding header. Throwing an error above works as advertised.

I'm using PHP 5.4.4.

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

Include in other project, return in html area

Thanks for your nice project.
I would like to include this in my small debugging plugin for WordPress, its easier to use without coding and also on client sites.
But i inlcude all returns in an html area, for use in tabs and view only, wat is important.

But i dont find not an hint in your documentatino, how it is possible to include this without an direkt echo at start.
maybe you can help me?

If you see on my project, than you find an small example on the inc/about.phphow works my retur of input and you can also see this on the scrrenshoot inside the repo.
https://github.com/bueltge/Debug-Objects

Thanks!

show more code from above than below in code snippets

Currently code snippets grab an equal amount from above and below.

This change will grab more content from above, as it's usually more important. So it will search up two thirds of the number of line numbers, and down by one third.

Php-error detect it's own errors

Hi,

I just installed php-error but i can do nothing with it because of the session_start();

"A session had already been started - ignoring session_start();"

It's doing this when i include the class after my session_start().
If i include it after, my user session is deleted (??) and i can't connect...

Is this a bug ? or is there a way to prevent it form detecting it's own errors ?
Thanks !
It will be a very useful tool

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.

a method to dynamically loosen error reporting

a modern framework might have two realms of PHP code - actual code and templates, and in templates the codestyle might be more forgiving of stuff like undefined array indices, etc

it would be nice to have an API call to loosen the error reporting a bit once the code hits the stage where it's done all the heavy lifting and all it has to do is render the HTML

it can currently be achieved by just disabling the error handler, but it would be nice to still get the nice error page if a more serious error is done in templates (undefined function, etc) while letting through stuff like undefined var/array element

Iterate through exceptions

It would be nice if you could iterate up the chain of exceptions to show a stack for each. I started this, but it will take more work than I have time for at the moment.

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.

Compatibility with Xdebug

Is there any way I can continue to have Xdebug enabled, but use PHP-Error just for error reporting?

session_start notice

<?php

// load the session, if it's there
if (isset($_COOKIE[session_name()])) {
    session_start();
}

Suggest an additional if check eg

<?php

// load the session, if it's there
if (isset($_COOKIE[session_name()]) && empty($_SESSION)) {
    session_start();
}

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?

Broken with "zlib output compression"

changed line 1515 to
} else if ( $handler === 'default output handler' || $handler === 'zlib output compression' ) {

fixed the issue... was getting a blank page due to ob_end_flush being called.

When an error occurres, add a way to re-run, and print the value of a variable

Add a button that re-runs the error, but stores and displays the values of every variable within the code snippets.The code snippets will display all of those values within them, instead of variables, which can switch between.

Behind it scenes it would achieve this by copying the code, inject code into the copy to do the printing, and re-run using the altered code, to retrieve the values.

  • Temporary files could be used as a place for storing the copy.
  • A copy should always be altered, not the original, in case it goes horribly wrong.
  • some autoloader magic might allow injecting the copy into 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

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 71 bytes)

Hi

I am getting the below Fatal error when I re-index groupscatalog2_product manually, any idea why and what I can do to fix it.

When I re-index groupscatalog2_category it indexes successfully, HELP :(

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 71 bytes) in /home/comamari/public_html/app/code/community/Netzarbeiter/GroupsCatalog2/Model/Resource/Indexer/Abstract.php on line 357

Do I need to increase php memory?

Many thanks

Amer Laldin (M.D)

Ajax XMLHttpRequest.timeout !!

Hello,

When I put your code on my application, i have this message on my console :

XMLHttpRequest.timeout cannot be set for synchronous HTTP(S) requests made from the window context. dev.supvize.com/index/2ec388d0bcd2cc5/:5

XMLHttpRequest.responseType cannot be changed for synchronous HTTP(S) requests made from the window context.

have you ever encounter this problem?

Thx.
capture decran 2013-09-27 a 11 15 12

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

move magic constant from HTML comment to header

Currently an ajax requests detects if the result is an error or not by searching for a magic comment which is next to the doctype. This is hacky, flakey, and has already proved to be problematic to work with.

Instead just set in the header that it's an error stack trace, and have the JS check for this on the result.

This should also make the on ready state change function less likely to break (as I suspect it's not perfect).

Missing $_SERVER['QUERY_STRING']

If I run internal server in PHP 5.4, PHP-Error throws error on line 3045. The QUERY_STRING is missing in $_SERVER for url localhost.

Images generated via PHP are broken

The JS injection code seems to run when PHP generates an image. For reference, the following headers are set when generating the image:

  • Pragma: public
  • Expires: 0
  • Cache-Control: must-revalidate, post-check=0, pre-check=0
  • Content-Transfer-Encoding: binary
  • Content-type: image/png

allow PHP Error to let existing handlers, go first

Currently, PHP Error replaces any existing handlers, and just forces it's self to become the main handler. The problem here, is that people are using PHP Error with existing code, which has existing error handlers.

So PHP Error needs some mechanism for working with these in different ways, and some policy about how it works in relation to others.

According to the PHP docs, a handler is supposed to return true, if the error has been handled. So in theory, PHP Error could run any existing handler set before it, and only run if that handler failed to return true.

The debate comes down to what the default context should be. The way I see it, the options are:

  • People are using PHP Error to replace any existing error handling, and so should take over the error handler. In this scenario, an option is provided to allow PHP Error to run existing handlers first.
  • People want to use PHP Error as a fallback for existing error handling, and so should always let an existing handler go first. An option is provided, for PHP Error to ignore this, and let an existing handler go first.

The default behaviour can be decided later, but for now the code should be changed to capture any existing handlers, and allow them to be run before the current handler. A boolean option can then decide if that is on or not (with the default set in the __construct).

php_error conflicting js?

After applying #8's fix, I now find javascript failing left and right and resources not being loaded. Not entirely sure why. Nothing in the error log to aid with this one.

Eg the admin panel

add option to disable via ini

Add an ini option, to disable this script. If present this will silently do nothing.

This is so if it does get slipped into production, it can be locked down, by default.

Option to change how superglobals are dumped

Problem is, that for my $_POST dump there are only the values. Since it's an associative array in my case i need to know what values belong to what keys and what keys are set and what not. It would be great if you could configure php error in such way, that it's possible to choose between a simple dump (current style) or a full dump in good old print_r/var_dump style.

Symfony2

Anyone try using this library for Symfony2?

spl_autoload loading an unrelated class?

[02-Jul-2012 16:07:11 UTC] Class 'jigoshop_product' not found
           C:\wamp\php\php_error.php, 2034
        #0 C:\wamp\php\php_error.php(2368): php_error\ErrorHandler->reportClassNotFound('jigoshop_produc...')
        #1 [internal function]: php_error\{closure}('jigoshop_produc...')
        #2 [internal function]: spl_autoload_call('jigoshop_produc...')
        #3 C:\wamp\www\envato\php-login-user-manage\header.php(3): session_start()
        #4 C:\wamp\www\envato\php-login-user-manage\home.php(1): include_once('C:\wamp\www\env...')
        #5 {main}

On a completely unrelated script from Wordpress, separate directory etc, it seems php_error.php is trying to verify the class jigoshop_product? Jigoshop is a Wordpress plugin.

I don't think this will help but here's the output:

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?

White page when application using output buffers triggers notice/warning.

Cleaning output buffers (preferably in a loop as buffers can be nested) in ErrorHandler->discardBuffer() solves the problem.

The following code recreates the problem:

<?php

ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
error_reporting(-1);
require_once('../library/php_error.php');
\php_error\reportErrors();

ob_start();

echo "before";
trigger_error("ERROR", E_USER_NOTICE);
echo "after";

ob_flush();

set editor shortcuts

These are keyboard shortcut changes.

The follow needs to be removed:

  • ctrl+r shortcut needs to be disabled, so it returns to be reload page; change to ctrl+h (which is used by Notepad++)

The following needs to be added:

  • ctrl+up, move up stack trace, displays that stack in the editor
  • ctrl+down, move down stack trace, displays that stack in the editor
  • ctrl+s, save changes and reload

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.