Whippet::emit_php_error PHP Method

emit_php_error() public static method

This function actually emits handled PHP errors. It's here instead of in handle_php_error because we want a static version to be used from the bootstrap script.
public static emit_php_error ( $number, $error, $file, $line, $options = ['show-errors' => E_ALL] )
    public static function emit_php_error($number, $error, $file, $line, $options = array('show-errors' => E_ALL))
    {
        if ($number != E_ERROR && !isset($options['show-wp-errors']) && Whippet::file_is_in_core($file, $options)) {
            return;
        }
        $error_type = array(E_ERROR => 'Fatal error', E_WARNING => 'Warning', E_PARSE => 'Parsing error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core error', E_CORE_WARNING => 'Core warning', E_COMPILE_ERROR => 'Compile error', E_COMPILE_WARNING => 'Compile warning', E_USER_ERROR => 'User error', E_USER_WARNING => 'User warning', E_USER_NOTICE => 'User notice', E_STRICT => 'Strict notice', E_RECOVERABLE_ERROR => 'Recoverable error', E_DEPRECATED => 'Deprecated', E_USER_DEPRECATED => 'User Deprecated');
        // If the error is unknown, pass it through directly
        if (empty($error_type[$number])) {
            $error_type[$number] = $number;
        }
        // Should we show this error?
        if (($number & $options['show-errors']) != $number) {
            return;
        }
        // Display the error
        Whippet::message(Colours::fg('bold_red') . $error_type[$number] . Colours::fg('red') . ": " . $error . Colours::fg('brown') . " in " . $file . " at line {$line}" . Colours::off());
        // Show a notification, if we've got libnotify
        if (!empty($options['libnotify']) && $number === E_ERROR) {
            $message = "{$error_type[$number]}: {$error} in {$file} at line {$line}";
            $message = str_replace("'", "\\'", $message);
            exec("{$options['libnotify']} -i error 'Whippet' '{$message}'");
        }
    }

Usage Example

Ejemplo n.º 1
0
//
// The file gets deleted when the user quits.
//
$handle = popen("echo '{$valid_arguments}' | " . PHP_BINARY . " -S {$options['i']}:{$options['p']} " . dirname(__FILE__) . "/lib/router.php 2>&1", 'r');
while (!feof($handle)) {
    $line = fgets($handle);
    //
    // Output filters
    // Run any filters that should be run on the output, and decide if we want to display it.
    //
    // Deal with PHP errors that the error handler can't manage
    if (preg_match('/(\\[.+\\]) (PHP .+):  (.+) in (.+) on line (\\d+)$/', $line, $matches)) {
        $number = $matches[2];
        switch ($matches[2]) {
            case "PHP Parse error":
                $number = E_PARSE;
            case "PHP Fatal error":
                $number = E_ERROR;
        }
        Whippet::emit_php_error($number, $matches[3], $matches[4], $matches[5], $options);
        continue;
    }
    // Other stuff that comes out of PHP -S (only seen invalid request warnings so far)
    if (preg_match('/\\[\\w\\w\\w \\w\\w\\w [\\d\\s:]+\\] (.+)$/', $line, $matches)) {
        Whippet::message(Colours::fg('blue') . "Server: " . Colours::fg('white') . $matches[1]);
        continue;
    }
    echo $line;
}
// We'll never get here.
echo "Kosinski: The truth is, Captain, I made a mistake - a wonderful, incredible mistake...\n";