SError::getError PHP Method

getError() public static method

public static getError ( $backtrace, $e = null ) : string
return string
    public static function getError($backtrace, $e = null)
    {
        if (PHP_SAPI == "cli") {
            $arrLen = count($backtrace);
            $text = "\r\n" . (empty($e) ? "Error" : "Exception") . "(" . date("Y-m-d H:i:s") . ")\r\n";
            $index = 0;
            if ($arrLen > 0) {
                for ($i = $arrLen - 1; $i > 0; $i--) {
                    $line = isset($backtrace[$i]['line']) ? $backtrace[$i]['line'] : "";
                    $file = isset($backtrace[$i]['file']) ? $backtrace[$i]['file'] : "";
                    $class = isset($backtrace[$i]['class']) ? $backtrace[$i]['class'] : "";
                    $func = isset($backtrace[$i]['function']) ? $backtrace[$i]['function'] : "";
                    $text .= $index++ . "\t" . $file . "({$line})\t" . (empty($class) ? "" : $class . '::') . $func . "(";
                    if (!empty($backtrace[$i]['args'])) {
                        $text .= self::args2str($backtrace[$i]['args']);
                    }
                    $text .= ")\r\n";
                }
            }
            $i = 0;
            if ($e) {
                $text .= $index++ . "\t" . $e->getFile() . "(" . $e->getLine() . ")\t" . $e->getCode() . ":" . $e->getMessage() . "\t\r\n";
            } else {
                $errorCode = $backtrace[$i]['args'][0];
                $line = isset($backtrace[$i]['line']) ? $backtrace[$i]['line'] : "";
                $text .= $index++ . "\t" . @$backtrace[$i]['args'][2] . "({$line})\t" . SError::$error_type[$errorCode] . ':' . (!empty($backtrace[$i]['args']) ? $backtrace[$i]['args'][1] : "") . "\r\n";
            }
            return $text;
        } else {
            $arrLen = count($backtrace);
            $html = "\r\n" . '<table border="1" cellpadding="3" style="font-size: 75%;border: 1px solid #000000;border-collapse: collapse;"><tr style="background-color: #ccccff; font-weight: bold; color: #000000;"><th style="padding:4px">#</th><th style="padding:4px">File</th><th style="padding:4px">Line</th><th style="padding:4px">Class::Method(Args)</th><th style="padding:4px">' . (empty($e) ? "Error" : "Exception") . '</th></tr>';
            $index = 0;
            if ($arrLen > 0) {
                for ($i = $arrLen - 1; $i > 0; $i--) {
                    $line = isset($backtrace[$i]['line']) ? $backtrace[$i]['line'] : "";
                    $file = isset($backtrace[$i]['file']) ? $backtrace[$i]['file'] : "";
                    $class = isset($backtrace[$i]['class']) ? $backtrace[$i]['class'] : "";
                    $type = isset($backtrace[$i]['type']) ? $backtrace[$i]['type'] : "";
                    $func = isset($backtrace[$i]['function']) ? $backtrace[$i]['function'] : "";
                    $html .= '<tr style="background-color: #cccccc; color: #000000;"><td>' . $index++ . '</td><td style="padding:4px">' . $file . '</td><td style="padding:4px">' . $line . '</td><td style="padding:4px">' . (empty($class) ? "" : $class . $type) . $func . '(';
                    if (!empty($backtrace[$i]['args'])) {
                        $html .= self::args2str($backtrace[$i]['args']);
                    }
                    $html .= ')<td></td></tr>';
                }
            }
            $i = 0;
            if ($e) {
                $html .= '<tr style="background-color: #cccccc; color: #000000;"><td style="padding:4px">' . $index++ . '</td><td style="padding:4px">' . $e->getFile() . '</td><td style="padding:4px">' . $e->getLine() . '</td><td></td><td style="padding:4px;font-weight:bold">' . $e->getCode() . ':' . $e->getMessage() . '</td></tr>';
            } else {
                $errorCode = $backtrace[$i]['args'][0];
                $line = empty($backtrace[$i]['line']) ? 0 : $backtrace[$i]['line'];
                $html .= '<tr style="background-color: #cccccc; color: #000000;"><td style="padding:4px">' . $index++ . '</td><td style="padding:4px">' . $backtrace[$i]['args'][2] . '</td><td style="padding:4px">' . $line . '</td><td></td><td style="padding:4px;font-weight:bold">' . SError::$error_type[$errorCode] . ':' . (!empty($backtrace[$i]['args']) ? $backtrace[$i]['args'][1] : "") . '</td></tr>';
            }
            $html .= '</table><hr style="background-color: #cccccc; border: 0px; height: 1px;" />' . "\r\n\r\n";
            return $html;
        }
    }

Usage Example

Ejemplo n.º 1
0
 public static function error_handler($errno, $errstr, $errfile, $errline)
 {
     $log = SError::getError(debug_backtrace());
     if (SError::$CONSOLE) {
         echo $log;
     }
     if (SError::$LOG) {
         if (!empty(SError::$LOGFILE)) {
             error_log($log, 3, SError::$LOGFILE);
         } else {
             error_log($log);
         }
     }
 }