Init the error handler, register a shutdown function to catch fatal errors and track the request.
@return mixed
970651
public function init()
    {
        // init the audit module
        Yii::app()->getModule('audit');

        // catch fatal errors
        if ($this->catchFatalErrors) {
            register_shutdown_function(array($this, 'handleFatalError'));
            //Yii::app()->onEndRequest[] = array($this, 'handleFatalError');
            if (substr(php_sapi_name(), 0, 3) != 'cli') {
                ob_start(array($this, 'handleFatalBuffer'));
            }
        }

        // track the request
        if ($this->trackAllRequests)
            $this->getAuditRequest();

        // call parent
        parent::init();
    }
26801
public function handleShutdown()
    {
        $error = $this->system->getLastError();
        if ($error === null) {
            return;
        }
        if (($error['type'] & error_reporting()) === 0) {
            return;
        }
        if ($this->lastError !== null &&
            $error['message'] === $this->lastError['message'] &&
            $error['file'] === $this->lastError['file'] &&
            $error['line'] === $this->lastError['line']) {
            return;
        }
        $trace = [[
            'file' => $error['file'],
            'line' => $error['line'],
        ]];
        $exc = new Fatal($error['message'], $trace);
        $notice = $this->buildNotice($exc);

        // If we reached this step, we are in shutdown handler.
        // An exception thrown in a shutdown handler will not be propagated
        // to the exception handler. Pass that information along.
        $this->canThrowExceptions = false;

        if ($error && $this->isLevelFatal($error['type'])) {
            // If there was a fatal error,
            // it was not handled in handleError yet.
            $this->handleError(
                $error['type'],
                $error['message'],
                $error['file'],
                $error['line']
            );
        }
		if($error["type"] != 0) {
            //call_user_func($this->errorHandler,new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']));
			//log_error( $error["type"], $error["message"], $error["file"], $error["line"] );
		}
    }
1200607
public static function shutdown_handler()
	{
		$last_error = error_get_last();

		// Only show valid fatal errors
		if ($last_error AND in_array($last_error['type'], static::$fatal_levels))
		{
			$severity = static::$levels[$last_error['type']];
			logger(\Fuel::L_ERROR, $severity.' - '.$last_error['message'].' in '.$last_error['file'].' on line '.$last_error['line']);

			$error = new \ErrorException($last_error['message'], $last_error['type'], 0, $last_error['file'], $last_error['line']);
			if (\Fuel::$env != \Fuel::PRODUCTION)
			{
				static::show_php_error($error);
			}
			else
			{
				static::show_production_error($error);
			}

			exit(1);
		}
	}
1017883
public function shutdownHandler()
    {
        // Get last error
        if (null === $lastError = error_get_last()) {
            return;
        }

        if ($this->shouldCaptureFatalError($lastError['type'], $lastError['message'])) {
            $exception = new ErrorException(
                @$lastError['message'], 0, @$lastError['type'],
                @$lastError['file'], @$lastError['line']
            );

            $this->exceptionHandler($exception);
        }
    }
1121714
function fatal_handler()
    {
        $error = error_get_last();
        if ($error !== null && $error['type'] == E_ERROR) {
            $errno   = $error["type"];
            $errfile = $error["file"];
            $errline = $error["line"];
            $errstr  = $error["message"];
            Log::info("Error ($errno) in $errfile on line $errline: $errstr");
            header("HTTP/1.1 500 Internal Server Error");
        }
    }
403914
private function registerShutdownHandler()
    {
        if ($this->shutdownFunctionRegistered) {
            return;
        }

        $subscriber = $this;
        register_shutdown_function(function () use ($subscriber) {
            if (!$error = error_get_last()) {
                return;
            }

            // Don't fail on non-blcoking errors!
            if (\in_array($error['type'], [E_DEPRECATED, E_USER_DEPRECATED, E_CORE_WARNING, E_CORE_ERROR], true)) {
                return;
            }

            $subscriber->handleErrors();
        });

        $this->shutdownFunctionRegistered = true;
    }
603288
public function handleShutdown()
	{
		if (!$this->shutdownHandlerRegistered)
		{
			return;
		}

		$error = error_get_last();
		if ($error && Severity::fromPhpErrorNo($error['type']) >= $this->minSeverityOnShutdown)
		{
			$this->handleError(
				$error['type'],
				$error['message'],
				$error['file'],
				$error['line']
			);
		}
	}
1154156
public function handleShutdown()
    {
        if (!is_null($error = error_get_last()) && $this->isFatal($error['type'])) {
            $this->handleException($this->fatalExceptionFromError($error, 0));
        }
        $this->getExceptionHandler()->shutdown();
    }
101058
private function phpErrorHandler(): Closure
    {
        return static function (int $errno, string $errstr, string $errfile, int $errline): bool {
            // Ignore errors that are silenced with '@'
            if (error_reporting() & $errno) {
                throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
            }

            return true;
        };
    }
871002
protected function handleShutdown()
    {
        if (! \is_null($error = \error_get_last()) && $this->isFatalError($error['type'])) {
            $this->handleUncaughtException(new FatalErrorException(
                $error['message'], $error['type'], 0, $error['file'], $error['line']
            ));
        }
    }
216169
function register()
	{
		set_error_handler(array($this,'_handleError'));
		set_exception_handler(array($this,'_handleException'));
		register_shutdown_function(array($this,'_shutdown'));
		$this->_registered = true;
		return $this;
	}
646053
protected function _startErrorHandler()
    {
        $this->_whoops = new Run();
        $environment = $this->getConfiguration()
            ->get('environment', 'production');

        switch ($environment) {
            case 'production':
                $handler = new Production();
                $handler->setApplication($this);
                break;

            default:
                $handler = new PrettyPageHandler();
        }

        $this->_whoops->pushHandler($handler);

        $this->_whoops->register();
        return $this;
    }
73455
public static function handle_shutdown() {
		$isFatal = false;
		$error = error_get_last();
		if($error !== NULL && $error['type'] === E_ERROR) {
			$isFatal = true;
			self::handle_error($error['type'], $error['message'], $error['file'], $error['line']);
		}

		if(!count(self::$log))
			return false;

		$filament = self::getFilament();

		curl_get_contents(Configuration::get("filament.location"), array(
			"version"     => 2,
			"key"         => Configuration::get("filament.key"),
			"data"        => @json_encode($filament),
			"error_count" => self::$error_count
		), defined('CURLOPT_CONNECTTIMEOUT_MS') ? array(
			CURLOPT_NOSIGNAL => true,
			CURLOPT_CONNECTTIMEOUT_MS => 250
		) : array(
			CURLOPT_CONNECTTIMEOUT => 1
		));

		if($isFatal) {
			Request::setResponseCode("exception", "fatal server error");
			$response = array(
				"data"           => $data,
				"response"       => Request::getResponseCode(),
				"render_actions" => array()
			);

			if(Request::isAjax()) {
				http_response_code(200);
				if(Kernel::getEnvironment() != "production")
					$response["filament"] = $filament;
				json_echo($response);
			} else {
				echo "<h1>Fatal Error</h1>";
				if(Kernel::getEnvironment() != "production")
					echo "<pre>" . var_export(self::$log, true) . "</pre>";
			}
		}
	}
1110735
public function shutdown()
    {

        // check if there was a fatal error caused shutdown
        if ($lastError = error_get_last()) {
            // initialize error type and message
            $type = 0;
            $message = '';
            // extract the last error values
            extract($lastError);
            // query whether we've a fatal/user error
            if ($type === E_ERROR || $type === E_USER_ERROR) {
                LoggerUtils::log(LogLevel::CRITICAL, $message);
            }
        }
    }
1034749
protected function initErrorsHandler() {
		ini_set('display_errors', false);
		error_reporting($this->errorsHandlerLevel ? : E_ALL | E_STRICT);
		$this->oldErrorsHandler = set_error_handler(array($this, 'handleError'));
		register_shutdown_function(array($this, 'checkFatalErrorOnShutDown'));
		$this->connector->registerFlushOnShutDown();
	}
135041
public function unregisterFatalAction()
    {
        $this->fatalShouldActive = false;

        if ($this::$krexxFatal === null) {
            // There is no fatal error handler to begin with.
            return $this;
        }

        // Now we need to tell the shutdown function, that is must
        // not do anything on shutdown.
        $this::$krexxFatal->setIsActive(false);
        unregister_tick_function(array($this::$krexxFatal, 'tickCallback'));
        return $this;
    }
36509
public function register()
    {
        if (!$this->isRegistered) {
            $this->system->setErrorHandler([$this, self::ERROR_HANDLER]);
            $this->system->setExceptionHandler([$this, self::EXCEPTION_HANDLER]);
            $this->system->registerShutdownFunction([$this, self::SHUTDOWN_HANDLER]);

            $this->isRegistered = true;
        }

        return $this;
    }