Internal error handler
@param $errno
@param $errstr
@param null $errfile
@param null $errline
@param array $errcontext
324672
public static function errorHandler($errno, $errstr, $errfile = null, $errline = null, array $errcontext = array())
    {
//echo __METHOD__;
        if (!(error_reporting() & $errno)) {
            return;
        }
        self::exceptionHandler(
            new Error($errstr, Response::STATUS_ERROR, $errfile, $errline)
        );
    }
851836
public static function log_error($errno, $errstr, $errfile, $errline){
    if ( \defined('BBN_DATA_PATH') ){
      if ( is_dir(BBN_DATA_PATH.'logs') ){
        $file = BBN_DATA_PATH.'logs/_php_error.json';
        $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 20);
        $r = false;
        if ( is_file($file) ){
          $r = json_decode(file_get_contents($file), 1);
        }
        if ( !$r ){
          $r = [];
        }
        $t = date('Y-m-d H:i:s');
        if ( class_exists('\\bbn\\mvc') ){
          $mvc = mvc::get_instance();
        }
        $idx = self::find($r, [
          'type' => $errno,
          'error' => $errstr,
          'file' => $errfile,
          'line' => $errline,
          'request' => ''
        ]);
        if ( $idx !== false ){
          $r[$idx]['count']++;
          $r[$idx]['last_date'] = $t;
          $r[$idx]['backtrace'] = $backtrace;
        }
        else{
          $r[] = [
            'first_date' => $t,
            'last_date' => $t,
            'count' => 1,
            'type' => $errno,
            'error' => $errstr,
            'file' => $errfile,
            'line' => $errline,
            'backtrace' => $backtrace,
            'request' => ''
            //'context' => $context
          ];
        }
        self::sort_by($r, 'last_date', 'DESC');
        file_put_contents($file, json_encode($r, JSON_PRETTY_PRINT));
      }
      if ( $errno > 8 ){
        die($errstr);
      }
    }
    return false;
  }
740676
public static function php_error_handler($errno, $errstr, $errfile, $errline, $errcontext) {
        if($errno & error_reporting()) {
            foreach(self::$error_handling_instances as list($logger, $level, $with_line, $with_trace)) {
                if(!($errno & $level)) {
                    continue;
                }

                switch($errno) {
                    case E_PARSE:
                        $severity = Message::ALERT;
                        break;
                    case E_CORE_ERROR:
                    case E_COMPILE_ERROR:
                        $severity = Message::CRITICAL;
                        break;
                    case E_ERROR:
                    case E_USER_ERROR:
                    case E_RECOVERABLE_ERROR:
                        $severity = Message::ERROR;
                        break;
                    case E_WARNING:
                    case E_CORE_WARNING:
                    case E_COMPILE_WARNING:
                    case E_USER_WARNING:
                        $severity = Message::WARNING;
                        break;
                    case E_NOTICE:
                    case E_USER_NOTICE:
                        $severity = Message::NOTICE;
                        break;
                    case E_DEPRECATED:
                    case E_USER_DEPRECATED:
                        $severity = Message::INFO;
                        break;
                    case E_STRICT:
                    default:
                        $severity = Message::DEBUG;
                        break;
                }

                $message = self::errnoToString($errno).": $errstr";

                if($with_line) {
                    $message = "$message in $errfile on line: $errline";
                }

                if($with_trace) {
                    throw new Exception("Not implemented yet.");
                }

                $logger->logMessage(new Message($message, $severity));
            }
        }

        return TRUE;
    }
143007
private function addError($err, $offset = 0)
    {
        $info = $this->source->getDebugInfo($offset);
        $this->sdopx->rethrow($err, $info['line'], $info['src']);
    }
1144963
public function setErrorHandle($err, $message, $file, $line) {
        $oJsonRpc = JsonRpc::getInstance();
        $content = explode("\n", file_get_contents($file));
        header('Content-Type: application/json');
        $id = $oJsonRpc->extractId();
        $error = array(
           "code" => 100,
           "message" => "Server error",
           "error" => array(
              "name" => "PHPErorr",
              "code" => $err,
              "message" => $message,
              "file" => $file,
              "at" => $line,
              "line" => $content[$line-1]));
        ob_end_clean();
        echo $oJsonRpc->response(null, $id, $error);
        exit();
    }
146258
protected function _loadFileErrorHandler($errno, $errstr, $errfile, $errline)
    {
        if ($this->_loadFileErrorStr === null) {
            $this->_loadFileErrorStr = $errstr;
        } else {
            $this->_loadFileErrorStr .= (PHP_EOL . $errstr);
        }
    }
1065674
private function createErrorHandler()
    {
        /**
         * @param int $errno
         * @param string $errstr
         * @param string $errfile
         * @param int $errline
         * @return void
         * @throws \ErrorException if error is not within the error_reporting mask.
         */
        return function ($errno, $errstr, $errfile, $errline) {
            if (! (error_reporting() & $errno)) {
                // error_reporting does not include this error
                return;
            }

            throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
        };
    }
576276
function errorHandler( $errno, $errstr, $errfile, $errline )
    {
        if ( error_reporting() == 0 ) // @ error-control operator is used
            return;
        if ( !eZDebug::isDebugEnabled() )
            return;
        $str = "$errstr in $errfile on line $errline";
        if ( empty( $GLOBALS['eZDebugPHPErrorNames'] ) )
        {
            $GLOBALS['eZDebugPHPErrorNames'] =
                array( E_ERROR => 'E_ERROR',
                       E_PARSE => 'E_PARSE',
                       E_CORE_ERROR => 'E_CORE_ERROR',
                       E_COMPILE_ERROR => 'E_COMPILE_ERROR',
                       E_USER_ERROR => 'E_USER_ERROR',
                       E_WARNING => 'E_WARNING',
                       E_CORE_WARNING => 'E_CORE_WARNING',
                       E_COMPILE_WARNING => 'E_COMPILE_WARNING',
                       E_USER_WARNING => 'E_USER_WARNING',
                       E_NOTICE => 'E_NOTICE',
                       E_USER_NOTICE => 'E_USER_NOTICE',
                       E_STRICT => 'E_STRICT' );
            // Since PHP 5.2
            if ( defined('E_RECOVERABLE_ERROR') )
                $GLOBALS['eZDebugPHPErrorNames'][E_RECOVERABLE_ERROR] = 'E_RECOVERABLE_ERROR';
            // Since PHP 5.3
            if ( defined('E_DEPRECATED') )
                $GLOBALS['eZDebugPHPErrorNames'][E_DEPRECATED] = 'E_DEPRECATED';
            if ( defined('E_USER_DEPRECATED') )
                $GLOBALS['eZDebugPHPErrorNames'][E_USER_DEPRECATED] = 'E_USER_DEPRECATED';

        }
        $errname = "Unknown error code ($errno)";
        if ( isset( $GLOBALS['eZDebugPHPErrorNames'][$errno] ) )
        {
            $errname = $GLOBALS['eZDebugPHPErrorNames'][$errno];
        }
        switch ( $errname )
        {
            case 'E_ERROR':
            case 'E_PARSE':
            case 'E_CORE_ERROR':
            case 'E_COMPILE_ERROR':
            case 'E_USER_ERROR':
            case 'E_RECOVERABLE_ERROR':
            {
                $this->writeError( $str, 'PHP: ' . $errname );
            } break;

            case 'E_WARNING':
            case 'E_CORE_WARNING':
            case 'E_COMPILE_WARNING':
            case 'E_USER_WARNING':
            case 'E_DEPRECATED':
            case 'E_USER_DEPRECATED':
            {
                $this->writeWarning( $str, 'PHP: ' . $errname );
            } break;

            case 'E_NOTICE':
            case 'E_USER_NOTICE':
            {
                $this->writeNotice( $str, 'PHP: ' . $errname );
            } break;

            case 'E_STRICT':
            {
                return $this->writeStrict( $str, 'PHP: ' . $errname );
            } break;
            default:
            {
                 $this->writeError( $str, 'PHP: ' . $errname );
            } break;
        }
    }
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;
        }
    }
518184
private static function _handleJsonError($errno)
    {
        $messages = array(
            JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
            JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
            JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON'
        );
        throw new \DomainException(
            isset($messages[$errno])
            ? $messages[$errno]
            : 'Unknown JSON error: ' . $errno
        );
    }
435651
public function handlePHPError($error_number, $error, $error_file, $error_line)
	{
		// respect the current error_reporting setting
		if((error_reporting() & $error_number) === 0)
			return;
		
		throw new PHPException($error_number, $error, $error_file, $error_line);
	}
921057
public function handleError($errno, $errstr, $errfile, $errline, array $errcontext = [])
    {
        $msg = sprintf('%s: %s', self::getErrorDescription($errno), $errstr);

        if ($errno & $this->thrownErrors) {
            throw new ErrorException($msg, 0, $errno, $errfile, $errline);
        }

        if ($this->logError($errno, $msg, $errfile, $errline)) {
            return true;
        }

        return false;
    }
65374
public function handleError($errno, $errstr, $errfile, $errline)
    {
        if (!$this['debug']) {
            return;
        }

        throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
    }
154783
private static function handleJsonError($errno) {
        $messages = array(
            JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
            JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
            JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON'
        );
        throw new \DomainException(isset($messages[$errno])
            ? $messages[$errno]
            : 'Unknown JSON error: ' . $errno
        );
    }
668787
public static function addError($errno, $errstr = '', $errfile = '', $errline = 0)
    {
        $stack = & static::$stack[count(static::$stack) - 1];
        $stack = new ErrorException($errstr, 0, $errno, $errfile, $errline, $stack);
    }
418724
public function OnUncaughtErrorTriggered($errSeverity, $errMessage, $errFile, $errLine, array $errContext)
    {
        //@call
        if (0 === error_reporting()) {
            return false;
        }
        throw new PHPTriggerErrorException($errMessage, $errLine, $errFile, $errSeverity);
    }
31358
public static function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
    {
        Daemon::$noError = false;
        $l = error_reporting();
        if ($l === 0) {
            if (!Daemon::$restrictErrorControl) {
                return;
            }
        } elseif (!($l & $errno)) {
            return;
        }

        static $errtypes = [
            E_ERROR => 'Fatal error',
            E_WARNING => 'Warning',
            E_PARSE => 'Parse error',
            E_NOTICE => 'Notice',
            E_PARSE => 'Parse error',
            E_USER_ERROR => 'Fatal error (userland)',
            E_USER_WARNING => 'Warning (userland)',
            E_USER_NOTICE => 'Notice (userland)',
            E_STRICT => 'Notice (userland)',
            E_RECOVERABLE_ERROR => 'Fatal error (recoverable)',
            E_DEPRECATED => 'Deprecated',
            E_USER_DEPRECATED => 'Deprecated (userland)',
        ];
        $errtype = $errtypes[$errno];
        Daemon::log($errtype . ': ' . $errstr . ' in ' . $errfile . ':' . $errline . "\n" . Debug::backtrace());
        if (Daemon::$context instanceof \PHPDaemon\Request\Generic) {
            Daemon::$context->out('<strong>' . $errtype . '</strong>: ' . $errstr . ' in ' . basename($errfile) . ':' . $errline . '<br />');
        }
    }