Catching PHP Errors

This article has moved.

About these ads

2 Comments to “Catching PHP Errors”

  1. hi,

    a small notice on “Type 3. Fatal Errors” and “error_get_last()”:
    PHP-internal-Exceptions are hybrid (Exceptions and Errors)!

    1. if you throw own exceptions “error_get_last()” returns NULL
    2. if PHP throws (internal!) exceptions “error_get_last()” returns exception-data!

    so you end up logging catched exceptions/errors.

    Code:

    ini_set('display_errors', true);
    date_default_timezone_set('UTC');

    try {
    throw new \Exception('crypto');
    } catch (\Exception $e) {
    echo 'Exception: ' . var_export($e, true) . '';
    }

    echo 'error_get_last: ' . var_export(error_get_last(), true) . '';

    try {
    new DateTime('compress');
    } catch (\Exception $e) {
    echo 'Exception: ' . var_export($e, true) . '';
    }

    echo 'error_get_last: ' . var_export(error_get_last(), true) . '';

    more info:
    http://de2.php.net/manual/en/errorfunc.configuration.php#ini.track-errors
    http://bugs.php.net/bug.php?id=54043

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: