Example #1
0
function errh($errno, $msg, $file, $line, $ctx = null)
{
    static $err = array(E_DEPRECATED => 'E_DEPRECATED          ', E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR   ', E_STRICT => 'E_STRICT              ', E_WARNING => 'E_WARNING             ', E_NOTICE => 'E_NOTICE              ', E_USER_ERROR => 'E_USER_ERROR          ', E_USER_WARNING => 'E_USER_WARNING        ', E_USER_NOTICE => 'E_USER_NOTICE         ', E_USER_DEPRECATED => 'E_USER_DEPRECATED     ', VERBOSE_INDEXING => 'Indexing              ', VERBOSE_FORMAT_RENDERING => 'Rendering Format      ', VERBOSE_THEME_RENDERING => 'Rendering Theme       ', VERBOSE_RENDER_STYLE => 'Rendering Style       ', VERBOSE_PARTIAL_READING => 'Partial Reading       ', VERBOSE_PARTIAL_CHILD_READING => 'Partial Child Reading ', VERBOSE_TOC_WRITING => 'Writing TOC           ', VERBOSE_CHUNK_WRITING => 'Writing Chunk         ', VERBOSE_MESSAGES => 'Heads up              ', VERBOSE_NOVERSION => 'No version information', VERBOSE_BROKEN_LINKS => 'Broken links          ', VERBOSE_OLD_LIBXML => 'Old libxml2           ', VERBOSE_MISSING_ATTRIBUTES => 'Missing attributes    ');
    static $recursive = false;
    // Respect the error_reporting setting
    if (!(error_reporting() & $errno)) {
        return false;
    }
    // Recursive protection
    if ($recursive) {
        // Thats bad.. lets print a backtrace right away
        debug_print_backtrace();
        // Fallback to the default errorhandler
        return false;
    }
    $recursive = true;
    $time = date(Config::date_format());
    switch ($errno) {
        case VERBOSE_INDEXING:
        case VERBOSE_FORMAT_RENDERING:
        case VERBOSE_THEME_RENDERING:
        case VERBOSE_RENDER_STYLE:
        case VERBOSE_PARTIAL_READING:
        case VERBOSE_PARTIAL_CHILD_READING:
        case VERBOSE_TOC_WRITING:
        case VERBOSE_CHUNK_WRITING:
        case VERBOSE_MESSAGES:
            $color = Config::phd_info_color();
            $output = Config::phd_info_output();
            $data = $msg;
            break;
        case VERBOSE_NOVERSION:
        case VERBOSE_BROKEN_LINKS:
        case VERBOSE_MISSING_ATTRIBUTES:
            $color = Config::phd_warning_color();
            $output = Config::phd_warning_output();
            $data = $msg;
            break;
            // User triggered errors
        // User triggered errors
        case E_USER_ERROR:
        case E_USER_WARNING:
        case E_USER_NOTICE:
            $color = Config::user_error_color();
            $output = Config::user_error_output();
            $data = sprintf("%s:%d\n\t%s", $file, $line, $msg);
            break;
            // PHP triggered errors
        // PHP triggered errors
        case E_DEPRECATED:
        case E_RECOVERABLE_ERROR:
        case E_STRICT:
        case E_WARNING:
        case E_NOTICE:
            $color = Config::php_error_color();
            $output = Config::php_error_output();
            $data = sprintf("%s:%d\n\t%s", $file, $line, $msg);
            break;
        default:
            $recursive = false;
            return false;
    }
    $timestamp = term_color(sprintf("[%s - %s]", $time, $err[$errno]), $color);
    fprintf($output, "%s %s\n", $timestamp, $data);
    // Abort on fatal errors
    if ($errno & (E_USER_ERROR | E_RECOVERABLE_ERROR)) {
        exit(1);
    }
    $recursive = false;
    return true;
}
Example #2
0
function errh($errno, $msg, $file, $line, $ctx = null)
{
    // will be set to a resource handle if we have an error
    $output = null;
    static $err = array(E_DEPRECATED => 'E_DEPRECATED          ', E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR   ', E_STRICT => 'E_STRICT              ', E_WARNING => 'E_WARNING             ', E_NOTICE => 'E_NOTICE              ', E_USER_ERROR => 'E_USER_ERROR          ', E_USER_WARNING => 'E_USER_WARNING        ', E_USER_NOTICE => 'E_USER_NOTICE         ', E_USER_DEPRECATED => 'E_USER_DEPRECATED     ', VERBOSE_INDEXING => 'Indexing              ', VERBOSE_FORMAT_RENDERING => 'Rendering Format      ', VERBOSE_THEME_RENDERING => 'Rendering Theme       ', VERBOSE_RENDER_STYLE => 'Rendering Style       ', VERBOSE_PARTIAL_READING => 'Partial Reading       ', VERBOSE_PARTIAL_CHILD_READING => 'Partial Child Reading ', VERBOSE_TOC_WRITING => 'Writing TOC           ', VERBOSE_CHUNK_WRITING => 'Writing Chunk         ', VERBOSE_MESSAGES => 'Heads up              ', VERBOSE_NOVERSION => 'No version information', VERBOSE_BROKEN_LINKS => 'Broken links          ', VERBOSE_OLD_LIBXML => 'Old libxml2           ', VERBOSE_MISSING_ATTRIBUTES => 'Missing attributes    ');
    static $recursive = false;
    // Respect the error_reporting setting
    if (!(error_reporting() & $errno)) {
        return false;
    }
    // Recursive protection
    if ($recursive) {
        // Thats bad.. lets print a backtrace right away
        debug_print_backtrace();
        // Fallback to the default errorhandler
        return false;
    }
    $recursive = true;
    if (!ini_get('date.timezone')) {
        date_default_timezone_set('America/Los_Angeles');
    }
    $time = date(Config::date_format());
    switch ($errno) {
        case VERBOSE_INDEXING:
        case VERBOSE_FORMAT_RENDERING:
        case VERBOSE_THEME_RENDERING:
        case VERBOSE_RENDER_STYLE:
        case VERBOSE_PARTIAL_READING:
        case VERBOSE_PARTIAL_CHILD_READING:
        case VERBOSE_TOC_WRITING:
        case VERBOSE_CHUNK_WRITING:
        case VERBOSE_MESSAGES:
            $color = Config::phd_info_color();
            $output = Config::phd_info_output();
            $data = $msg;
            break;
        case VERBOSE_NOVERSION:
        case VERBOSE_BROKEN_LINKS:
        case VERBOSE_MISSING_ATTRIBUTES:
            $color = Config::phd_warning_color();
            $output = Config::phd_warning_output();
            $data = $msg;
            break;
            // User triggered errors
        // User triggered errors
        case E_USER_ERROR:
        case E_USER_WARNING:
        case E_USER_NOTICE:
            $color = Config::user_error_color();
            $output = Config::user_error_output();
            $data = sprintf("%s:%d\n\t%s", $file, $line, $msg);
            break;
            // PHP triggered errors
        // PHP triggered errors
        case E_DEPRECATED:
        case E_RECOVERABLE_ERROR:
        case E_STRICT:
        case E_WARNING:
        case E_NOTICE:
            $color = Config::php_error_color();
            $output = Config::php_error_output();
            $data = sprintf("%s:%d\n\t%s", $file, $line, $msg);
            break;
        default:
            $recursive = false;
            return false;
    }
    if ($output === null) {
        // fallback to stdout. Why do I need this, when $output should
        // be set in the switch above? Well.......
        // Possible bug with the STDERR|IN|OUT constants and FASTCGI
        // https://github.com/facebook/hhvm/issues/2502
        // http://www.perlmonks.org/?node_id=108278
        // DevServer without FASTCGI - STDOUT is a normal resource strean
        // ProdServer with HHVM/FASTCGI - STDOUT is NULL. That's not good.
        // See Config::$optionArrayDefault in Config.php where STDOUT, etc.
        // are set for php_error_output, php_info_output, etc.
        $output = fopen('php://stdout', 'w');
    }
    $timestamp = term_color(sprintf("[%s - %s]", $time, $err[$errno]), $color);
    fprintf($output, "%s %s\n", $timestamp, $data);
    // Abort on fatal errors
    if ($errno & (E_USER_ERROR | E_RECOVERABLE_ERROR)) {
        exit(1);
    }
    $recursive = false;
    return true;
}