JosephLenton / PHP-Error

Better error reporting for PHP, and prettier too!
1.35k stars 152 forks source link

a method to dynamically loosen error reporting #44

Open allixsenos opened 11 years ago

allixsenos commented 11 years ago

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

MZAWeb commented 11 years ago

I think allowing this is not a good move. Developers should be aware of what they do, and do it right. But I can totally see the point of not having a black window blocking all for an index notice, for instance. Maybe a small error report at the top of the page and then render the site?

allixsenos commented 11 years ago

I've worked around it with

require_once 'data/includes/php_error.php';
$errorhandler = \php_error\reportErrors(array('error_reporting_on' => E_ALL | E_STRICT));

and then later down

if (!empty($errorhandler)) {
    $errorhandler->turnOff();
    $errorhandler = \php_error\reportErrors(array('error_reporting_on' => (E_ALL | E_STRICT) & ~E_NOTICE));
}

something like $errorhandler->change_error_reporting(...) would be nice