TODO

@param $errno
@param $errstr
@param $errfile
@param $errline
766374
function format_error($errno, $errstr, $errfile, $errline)
    {

        echo '
  <table>
  <thead><th>Item</th><th>Description</th></thead>
  <tbody>
  <tr>
    <th>Error</th>
    <td><pre>' . $errstr . '</pre></td>
  </tr>
  <tr>
    <th>Errno</th>
    <td><pre>' . $errno . '</pre></td>
  </tr>
  <tr>
    <th>File</th>
    <td>' . $errfile . '</td>
  </tr>
  <tr>
    <th>Line</th>
    <td>' . $errline . '</td>
  </tr>
  <tr>
    <th>Trace</th>
    <td><pre>';
        debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
        echo '</pre></td>
  </tr>
  </tbody>
  </table>';

        //        return $content;
    }
62526
public static function errToException($turnOn = true)
    {
        if (!$turnOn) {
            return set_error_handler(null);
        }

        /*
         * Error handler
         *
         * @param int $errno
         * @param string $errStr
         * @param string $errFile
         * @param int $errLine
         *
         * @throws ErrorException
         */
        $handler = function ($errno, $errStr, $errFile, $errLine) {
            // This error code is not included in error_reporting
            if (!(error_reporting() & $errno)) {
                return;
            }
            throw new ErrorException($errStr, 0, $errno, $errFile, $errLine);
        };

        return set_error_handler($handler);
    }
995399
public function handleError($errno, $errstr, $errfile, $errline) {
    $errorIsEnabled = (bool)($errno & ini_get('error_reporting'));

    // FATAL ERROR
    if(isset(self::$fatalErrors[$errno]) && $errorIsEnabled) {
      throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
    }

    // NON-FATAL ERROR/WARNING/NOTICE
    else if($errorIsEnabled) {
      $info = $errstr." in ".$errfile." on line ".$errline;
      self::$logger->logByErrorType($errno, $info);
    }
  }
180100
public static function throwErrorException($errno, $errstr, $errfile, $errline)
    {
        if (error_reporting() & $errno) { //check if error level is set
            throw new \ErrorException(
                sprintf('%s: %s', self::getErrorTypeString($errno), $errstr),
                0,
                $errno,
                $errfile,
                $errline
            );
        }
    }
836361
static public function handleSessionStartError($errno, $errstr, $errfile, $errline, $errcontext)
    {
        self::$sessionStartError = $errfile . '(Line:' . $errline . '): Error #' . $errno . ' ' . $errstr;
    }
65374
public function handleError($errno, $errstr, $errfile, $errline)
    {
        if (!$this['debug']) {
            return;
        }

        throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
    }
969327
final public static function errorHandler(string $err_no, string $err_msg, string $errfile, string $errline)
    {
        throw new Server500(new \ArrayObject(array("explain" => $err_msg,
            "type_error" => self::errorMap($err_no), "line_error" => $errline, "file_error" => $errfile)));
    }
413943
protected function _errorhandler_output($errstr, $backtrace, $errortype) {
		// output error
		$error = '<div class="dp_container">';
		$error .= '<div class="skyline">'.$errortype.'</div>';
		$error .= '<h1 class="exception">'.htmlspecialchars($errstr, ENT_QUOTES, 'UTF-8').'</h1>';

		$count = 0;
		foreach ($backtrace as $key => $value) {
			// only if file is available
			if (!empty($value['file']) && is_file($value['file'])) {
				$id_file = '_errorhandler_file_'.$this->errorcounter.'_'.$count;
				$id_args = 'errorhandler_args_'.$this->errorcounter.'_'.$count;
				$show = ($count === 0) ? 'style="display: block;"' : '';

				if ($count>0) {
					$call = $value['class'].$value['type'].$value['function'].'()';
					$error .= '<h2>'.$call.'</h2>';
				}

				// highlight the file name
				$file = preg_replace('=[^/]+$=', '<strong>$0</strong>', $value['file']);
				
				$error .= '<h3>'.$file.' (Line '.$value['line'].')</h3>';
				$error .= '<div class="file" id="'.$id_file.'" '.$show.'>'.$this->_getContent($value['file'], $value['line']).'<div style="clear: both;"></div></div>';

				if (count($value['args'])>0 and $count > 0) {
					$dump = htmlspecialchars(print_r($value['args'], true));
					$error .= '<h3>Arguments ('.count($value['args']).')</h3>';
					$error .= '<div class="args" id="'.$id_args.'">'.$dump.'</div>';
				}

				$count++;
			}
		}

		$error .= '</div>';

		// output css and js only at first call
		if ($this->errorcounter === 1) $error .= $this->_debug_styles();

		return $error;
	}
582094
public static function errorHandler($errno, $errstr, $errfile = null, $errline = null, $errcontext = null)
    {
        return true;
    }
1299898
public function handleError($errNumber, $errString, $errFile ='', $errLine = 0)
	{
		$interfaceSettings = $this->cmd->getConfigOpt('interface');
		$textColor = $interfaceSettings['error']['text_color'];
		$textBgColor = $interfaceSettings['error']['text_background'];

		$this->env->sendOutput('Error: ' . $errString, $textColor, $textBgColor);
		exit;
	}
497981
public static function handlerError($errno, $errstr, $errfile, $errline)
    {
        $bad = array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR);

        // set log file name
        switch ($errno) {
            case E_ERROR:             $fn = "error";                 break;
            case E_WARNING:           $fn = "warning";               break;
            case E_PARSE:             $fn = "parse";                 break;
            case E_NOTICE:            $fn = "notice";                break;
            case E_CORE_ERROR:        $fn = "core_error";            break;
            case E_CORE_WARNING:      $fn = "core_warning";          break;
            case E_COMPILE_ERROR:     $fn = "compile_error";         break;
            case E_COMPILE_WARNING:   $fn = "compile_warning";       break;
            case E_USER_ERROR:        $fn = "user_error";            break;
            case E_USER_WARNING:      $fn = "user_warning";          break;
            case E_USER_NOTICE:       $fn = "user_notice";           break;
            case E_STRICT:            $fn = "strict";                break;
            case E_RECOVERABLE_ERROR: $fn = "recoverable_error";     break;
            case E_DEPRECATED:        $fn = "deprecated";            break;
            case E_USER_DEPRECATED:   $fn = "user_deprecated";       break;
            case E_ALL:               $fn = "all";                   break;
            default:                  $fn = "__{$errno}__undefined"; break;
        }

        if(defined('PATH_ROOT')) {
            $errfile = str_replace(realpath(PATH_ROOT), '', $errfile);
        }

        $err_msg = strtoupper($fn) . ": {$errstr}\nLINE: {$errline}\nFILE: {$errfile}";

        // With this setup errors are displayed according to the error_reporting() setting
        // but all errors are logged to file, regardles of
        if(defined('DEBUG') && DEBUG && error_reporting() & $errno) {
            echo self::_skipFormating()
                ? $err_msg . PHP_EOL
                : sprintf("<pre>\n<p style='%s'>\n%s\n</p>\n</pre>\n\n", self::getFormattedCss(), $err_msg);
        }

        // all errors are logged
        if(!empty($fn)) {
            self::_writeLog($fn . self::$_extenstion, $err_msg);
            self::_writeLogJson($fn, $errstr, $errno, $errline, $errfile, debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS));
        }

        // On production setup, if bad errors occurs, send mail with parsed exception and terminate the script
        // DISABLED FOR NOW SINCE IT'S KILLING US AT THE MOMENT!!!!!
        // SWITCH TO EVENTS!!!!!
//         if(in_array($errno, $bad)) {
//             if(defined('DEBUG') && !DEBUG) {
//                 try {
//                     throw new \Exception($errstr);
//                 } catch (\Exception $e) {
//                     $msg = self::_parseException($e);
//                 }

//                 defined('EMAIL_DEBUG')
//                 && defined('EMAIL_DEBUG_FROM')
//                 && @mail (EMAIL_DEBUG, "PHP ERROR: {$errstr}", $msg, 'From: ' . EMAIL_DEBUG_FROM);
//             }
//             exit(1);
//         }
    }
230221
function(err) {
    switch (err.code) {
      case 1:
        return Error('CURLE_UNSUPPORTED_PROTOCOL');
      case 2:
        return Error('CURLE_FAILED_INIT');
      case 3:
        return Error('CURLE_URL_MALFORMAT');
      case 4:
        return Error('CURLE_NOT_BUILT_IN');
      case 5:
        return Error('CURLE_COULDNT_RESOLVE_PROXY');
      case 6:
        return Error('CURLE_COULDNT_RESOLVE_HOST');
      case 7:
        return Error('CURLE_COULDNT_CONNECT');
      case 8:
        return Error('CURLE_FTP_WEIRD_SERVER_REPLY');
      case 9:
        return Error('CURLE_REMOTE_ACCESS_DENIED');
      case 10:
        return Error('CURLE_FTP_ACCEPT_FAILED');
      case 11:
        return Error('CURLE_FTP_WEIRD_PASS_REPLY');
      case 12:
        return Error('CURLE_FTP_ACCEPT_TIMEOUT');
      case 13:
        return Error('CURLE_FTP_WEIRD_PASV_REPLY');
      case 14:
        return Error('CURLE_FTP_WEIRD_227_FORMAT');
      case 15:
        return Error('CURLE_FTP_CANT_GET_HOST');
      case 17:
        return Error('CURLE_FTP_COULDNT_SET_TYPE');
      case 18:
        return Error('CURLE_PARTIAL_FILE');
      case 19:
        return Error('CURLE_FTP_COULDNT_RETR_FILE');
      case 21:
        return Error('CURLE_QUOTE_ERROR');
      case 22:
        return Error('CURLE_HTTP_RETURNED_ERROR');
      case 23:
        return Error('CURLE_WRITE_ERROR');
      case 25:
        return Error('CURLE_UPLOAD_FAILED');
      case 26:
        return Error('CURLE_READ_ERROR');
      case 27:
        return Error('CURLE_OUT_OF_MEMORY');
      case 28:
        return Error('CURLE_OPERATION_TIMEDOUT');
      case 30:
        return Error('CURLE_FTP_PORT_FAILED');
      case 31:
        return Error('CURLE_FTP_COULDNT_USE_REST');
      case 33:
        return Error('CURLE_RANGE_ERROR');
      case 34:
        return Error('CURLE_HTTP_POST_ERROR');
      case 35:
        return Error('CURLE_SSL_CONNECT_ERROR');
      case 36:
        return Error('CURLE_BAD_DOWNLOAD_RESUME');
      case 37:
        return Error('CURLE_FILE_COULDNT_READ_FILE');
      case 38:
        return Error('CURLE_LDAP_CANNOT_BIND');
      case 39:
        return Error('CURLE_LDAP_SEARCH_FAILED');
      case 41:
        return Error('CURLE_FUNCTION_NOT_FOUND');
      case 42:
        return Error('CURLE_ABORTED_BY_CALLBACK');
      case 43:
        return Error('CURLE_BAD_FUNCTION_ARGUMENT');
      case 45:
        return Error('CURLE_INTERFACE_FAILED');
      case 47:
        return Error('CURLE_TOO_MANY_REDIRECTS');
      case 48:
        return Error('CURLE_UNKNOWN_OPTION');
      case 49:
        return Error('CURLE_TELNET_OPTION_SYNTAX');
      case 51:
        return Error('CURLE_PEER_FAILED_VERIFICATION');
      case 52:
        return Error('CURLE_GOT_NOTHING');
      case 53:
        return Error('CURLE_SSL_ENGINE_NOTFOUND');
      case 54:
        return Error('CURLE_SSL_ENGINE_SETFAILED');
      case 55:
        return Error('CURLE_SEND_ERROR');
      case 56:
        return Error('CURLE_RECV_ERROR');
      case 58:
        return Error('CURLE_SSL_CERTPROBLEM');
      case 59:
        return Error('CURLE_SSL_CIPHER');
      case 60:
        return Error('CURLE_SSL_CACERT');
      case 61:
        return Error('CURLE_BAD_CONTENT_ENCODING');
      case 62:
        return Error('CURLE_LDAP_INVALID_URL');
      case 63:
        return Error('CURLE_FILESIZE_EXCEEDED');
      case 64:
        return Error('CURLE_USE_SSL_FAILED');
      case 65:
        return Error('CURLE_SEND_FAIL_REWIND');
      case 66:
        return Error('CURLE_SSL_ENGINE_INITFAILED');
      case 67:
        return Error('CURLE_LOGIN_DENIED');
      case 68:
        return Error('CURLE_TFTP_NOTFOUND');
      case 69:
        return Error('CURLE_TFTP_PERM');
      case 70:
        return Error('CURLE_REMOTE_DISK_FULL');
      case 71:
        return Error('CURLE_TFTP_ILLEGAL');
      case 72:
        return Error('CURLE_TFTP_UNKNOWNID');
      case 73:
        return Error('CURLE_REMOTE_FILE_EXISTS');
      case 74:
        return Error('CURLE_TFTP_NOSUCHUSER');
      case 75:
        return Error('CURLE_CONV_FAILED');
      case 76:
        return Error('CURLE_CONV_REQD');
      case 77:
        return Error('CURLE_SSL_CACERT_BADFILE');
      case 78:
        return Error('CURLE_REMOTE_FILE_NOT_FOUND');
      case 79:
        return Error('CURLE_SSH');
      case 80:
        return Error('CURLE_SSL_SHUTDOWN_FAILED');
      case 81:
        return Error('CURLE_AGAIN');
      case 82:
        return Error('CURLE_SSL_CRL_BADFILE');
      case 83:
        return Error('CURLE_SSL_ISSUER_ERROR');
      case 84:
        return Error('CURLE_FTP_PRET_FAILED');
      case 85:
        return Error('CURLE_RTSP_CSEQ_ERROR');
      case 86:
        return Error('CURLE_RTSP_SESSION_ERROR');
      case 87:
        return Error('CURLE_FTP_BAD_FILE_LIST');
      case 88:
        return Error('CURLE_CHUNK_FAILED');
      case 89:
        return Error('CURLE_NO_CONNECTION_AVAILABLE');
      default:
        return err;
    }
  }
314050
public function error($errno, $error, $file, $line) {
        try {
            throw new MyException($error, $errno, $file, $line);
        } catch (MyException $e) {
            ERRORCODE($e);
        }
    }
93274
static function _handleErrors($error, $errstr = '', $errfile = '', $errline = 0)
    {
        $ErrorType = self::ERR_TYP_EXCEPTION;
        if (! $error instanceof \Exception) {
            if (interface_exists('Throwable', false) && $error instanceof \Throwable)
                VOID;
            else {
                $ErrorType = self::ERR_TYP_ERROR;

                ## handle errors
                $error = new ErrorException(
                    $errstr, $error, 1, $errfile, $errline
                );
            }
        }

        ## happen when start handleError() but within codeblock an exception rised
        ## so code follow will stop then we need cleanup to first exception stack
        while (self::getStackNum() && $Stack = &self::$_STACK[self::getStackNum()-1]) {
            if ($ErrorType === $Stack['error_type'])
                break;

            self::handleDone();
        }

        $Stack['has_handled_error'] = $error;

        // ...

        if (!isset($Stack['callable']) || $Stack['callable'] === null)
            return;

        $currLevel = self::getStackNum();
        try {
            ## call user error handler callable
            ## exception will passed as errno on exception catch
            call_user_func($Stack['callable'], $error);

        } catch (\Exception $e) {
            ## during handling an error if any exception happen it must handle with parent handler
            if (self::getStackNum() == $currLevel)
                ## close current handler if not, the handleDone may be called from within handler callable
                self::handleDone();

            if ($Stack['error_type'] == self::ERR_TYP_ERROR)
                ## Just throw exception, it might handled with exception handlers
                throw $e;

            $isHandled = false;
            while (self::hasHandling()) {
                $Stack = & self::$_STACK[self::getStackNum()-1];
                if ($Stack['error_type'] == self::ERR_TYP_EXCEPTION) {
                    $isHandled = true;
                    self::_handleErrors($e);
                    break;
                }

                self::handleDone();
            }

            if (!$isHandled)
                ## throw exception if it not handled
                throw $e;
        }
    }
1294176
protected function buildErrorTrace($errfile, $errline)
    {
        if ($this->captureErrorStacktraces) {
            $backTrace = $this->fetchErrorTrace();
            
            $backTrace = $this->stripShutdownFrames($backTrace);
            
            // Add the final frame
            array_unshift(
                $backTrace,
                array('file' => $errfile, 'line' => $errline)
            );
        } else {
            $backTrace = array();
        }
        
        return $backTrace;
    }
905946
public static function ExceptionErrorHandler($errno = 0, $errstr = null, $errfile = null, $errline = null)
    {
        // If error is suppressed with @, don't throw an exception
        if (error_reporting() === 0 || strpos($errstr, 'headers already sent') || ($errfile && strpos($errfile, 'vendor/amphp') !== false)) {
            return false;
        }

        throw new self($errstr, $errno, null, $errfile, $errline);
    }
206956
public function setErrFile($errFile, $append = true)
    {
        $this->errFile = $errFile;
        $this->appendErrFile = $append;

        return $this;
    }