Skip to content
PHP Ecosystem
Explore

ErrorHandler

API reference › PSR bridge › http › ErrorHandler

classyii2\extensions\psrbridge\http\ErrorHandler
Extendsyii\web\ErrorHandler » yii\base\ErrorHandler » yii\base\Component » yii\base\BaseObject
Implementsyii\base\Configurable
Sourcesrc/http/ErrorHandler.php

Handles exceptions with Yii error rendering and PSR-7 bridge support.

PropertyTypeDescriptionDefined by
$behaviors read-onlyarray<yii\base\Behavior<static>>List of behaviors attached to this component.yii\base\Component
$callStackItemViewstringThe path of the view file for rendering exceptions and errors call stack element. Default: '@yii/views/errorHandler/callStackItem.php'.yii\web\ErrorHandler
$defaultResponseConfigarray<string, mixed>Default configuration for creating fallback Response instances. Default: ['charset' => 'UTF-8'].ErrorHandler
$discardExistingOutputboolWhether to discard any existing page output before error display. Default: true.yii\base\ErrorHandler
$displayVarsarrayList of the PHP predefined variables that should be displayed on the error page. Default: ['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION']. Available since 2.0.7.yii\web\ErrorHandler
$errorActionstring|nullThe route (e.g. site/error) to the controller action that will be used to display external errors. Default: null.yii\web\ErrorHandler
$errorViewstringThe path of the view file for rendering exceptions without call stack information. Default: '@yii/views/errorHandler/error.php'.yii\web\ErrorHandler
$exceptionThrowable|nullThe exception that is being handled currently. Default: null.yii\base\ErrorHandler
$exceptionViewstringThe path of the view file for rendering exceptions. Default: '@yii/views/errorHandler/exception.php'.yii\web\ErrorHandler
$maxSourceLinesintMaximum number of source code lines to be displayed. Default: 19.yii\web\ErrorHandler
$maxTraceSourceLinesintMaximum number of trace source code lines to be displayed. Default: 13.yii\web\ErrorHandler
$memoryReserveSizeintSize of the memory reserve for handling fatal errors. Default: 1024 * 1024.ErrorHandler
$previousExceptionViewstringThe path of the view file for rendering previous exceptions. Default: '@yii/views/errorHandler/previousException.php'.yii\web\ErrorHandler
$response write-onlyResponseResponse instance with desired configuration.ErrorHandler
$silentExitOnExceptionboolIf true - handleException() will finish script with ExitCode::OK. false - ExitCode::UNSPECIFIED_ERROR. Default: null. Available since 2.0.36.yii\base\ErrorHandler
$traceLinestringTrace line with placeholders to be be substituted. Default: '{html}'. Available since 2.0.14.yii\web\ErrorHandler
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\Component
__clone()This method is called after the object is created by cloning an existing one.yii\base\Component
__get()Returns the value of a component property.yii\base\Component
__isset()Checks if a property is set, i.e. defined and not null.yii\base\Component
__set()Sets the value of a component property.yii\base\Component
__unset()Sets a component property to be null.yii\base\Component
addTypeLinks()Adds informational links to the given PHP type/class.yii\web\ErrorHandler
argumentsToString()Converts arguments array to its string representation.yii\web\ErrorHandler
attachBehavior()Attaches a behavior to this component.yii\base\Component
attachBehaviors()Attaches a list of behaviors to the component.yii\base\Component
behaviors()Returns a list of behaviors that this component should behave as.yii\base\Component
canGetProperty()Returns a value indicating whether a property can be read.yii\base\Component
canSetProperty()Returns a value indicating whether a property can be set.yii\base\Component
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
clearOutput()Discards active output buffers, retaining level 1 when YII_ENV_TEST is true.ErrorHandler
convertExceptionToString() staticConverts an exception into a simple string.yii\base\ErrorHandler
convertExceptionToVerboseString() staticConverts an exception into a string that has verbose information about the exception and its trace.yii\base\ErrorHandler
createFrameworkVersionLink()Creates string containing HTML link which refers to the page with the current version of the framework and version number text.yii\web\ErrorHandler
createHttpStatusLink()Creates HTML containing link to the page with the information on given HTTP status code.yii\web\ErrorHandler
createServerInformationLink()Creates string containing HTML link which refers to the home page of determined web-server software and its full name.yii\web\ErrorHandler
detachBehavior()Detaches a behavior from the component.yii\base\Component
detachBehaviors()Detaches all behaviors from the component.yii\base\Component
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.yii\base\Component
getBehavior()Returns the named behavior object.yii\base\Component
getBehaviors()Returns all behaviors attached to this component.yii\base\Component
getExceptionName()Returns human-readable exception name.yii\web\ErrorHandler
handleError()Handles PHP execution errors such as warnings and notices.yii\base\ErrorHandler
handleException()Logs an exception and renders a bridge Yii response without sending it.ErrorHandler
handleFatalError()Releases reserved memory before delegating fatal-error rendering to Yii.ErrorHandler
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.yii\base\Component
hasMethod()Returns a value indicating whether a method is defined.yii\base\Component
hasProperty()Returns a value indicating whether a property is defined for this component.yii\base\Component
htmlEncode()Converts special characters to HTML entities.yii\web\ErrorHandler
init()yii\base\ErrorHandler
isCoreFile()Determines whether given name of the file belongs to the framework.yii\web\ErrorHandler
logException()Logs the given exception.yii\base\ErrorHandler
off()Detaches an existing event handler from this component.yii\base\Component
on()Attaches an event handler to an event.yii\base\Component
register()Registers PHP handlers with one weak shutdown dispatcher per process.ErrorHandler
releaseResponse()Releases request references after emission and finalization.ErrorHandler
renderCallStack()Renders call stack.yii\web\ErrorHandler
renderCallStackItem()Renders a single call stack element.yii\web\ErrorHandler
renderFile()Renders a view file as a PHP script.yii\web\ErrorHandler
renderPreviousExceptions()Renders the previous exception stack for a given Exception.yii\web\ErrorHandler
renderRequest()Renders the global variables of the request.yii\web\ErrorHandler
setResponse()Sets the Response for error handling.ErrorHandler
trigger()Triggers an event.yii\base\Component
unregister()Restores PHP handlers and releases the current registration’s reserve.ErrorHandler
convertExceptionToArray() protectedConverts an exception into an array.yii\web\ErrorHandler
getTypeUrl() protectedReturns the informational link URL for a given PHP type/class.yii\web\ErrorHandler
handleFallbackExceptionMessage() protectedHandles fallback exception rendering when an error occurs during exception processing.ErrorHandler
renderException() protectedRenders the exception and produces a Response object with appropriate error content.ErrorHandler
shouldRenderSimpleHtml() protectedyii\web\ErrorHandler
triggerAfterRender() protectedTriggers EVENT_AFTER_RENDER and returns final HTML content.yii\web\ErrorHandler
EventTypeDescriptionDefined by
EVENT_SHUTDOWNyii\base\EventAn event that is triggered when the handler is called by shutdown function via handleFatalError(). Event name: 'shutdown'. Available since 2.0.46.yii\base\ErrorHandler
ConstantValueDescriptionDefined by
EVENT_AFTER_RENDER'afterRender'ErrorHandlerRenderEvent an event that is triggered after HTML error content is rendered. Available since 22.0.yii\web\ErrorHandler
public function clearOutput(): void

Discards active output buffers, retaining level 1 when YII_ENV_TEST is true.

public function handleException(Throwable $exception): yii2\extensions\psrbridge\http\Response

Logs an exception and renders a bridge Yii response without sending it.

Unregisters the current error handler while rendering. If logging or rendering fails, returns a fallback response. PSR conversion remains the caller’s responsibility.

Parameters

ParameterTypeDescription
$exceptionThrowableException to render.

Returns

Response: Yii response containing the rendered error.

public function handleFatalError(): mixed

Releases reserved memory before delegating fatal-error rendering to Yii.

Returns

mixed

public function register(): mixed

Registers PHP handlers with one weak shutdown dispatcher per process.

Returns

mixed

public function releaseResponse(): void

Releases request references after emission and finalization.

public function setResponse(yii2\extensions\psrbridge\http\Response $response): void

Sets the Response for error handling.

The provided Response will be used for error responses, preserving configuration such as format, charset, and formatters. The Response will be cleared of any existing data before use.

Parameters

ParameterTypeDescription
$responseResponseResponse instance with desired configuration.
public function unregister(): mixed

Restores PHP handlers and releases the current registration’s reserve.

Returns

mixed

protected function handleFallbackExceptionMessage(Throwable $exception, Throwable $previousException): yii2\extensions\psrbridge\http\Response

Handles fallback exception rendering when an error occurs during exception processing.

Produces a Response object with a generic error message and, in debug mode, includes detailed exception information and a sanitized snapshot of server variables, excluding sensitive keys.

Parameters

ParameterTypeDescription
$exceptionThrowableException thrown during error handling.
$previousExceptionThrowableOriginal exception that triggered error handling.

Returns

Response: Object containing the fallback error message and debug output if enabled.

protected function renderException(Throwable $exception): yii2\extensions\psrbridge\http\Response

Renders the exception and produces a Response object with appropriate error content.

Handles exception rendering for HTML, raw, and array formats, supporting custom error views and error actions.

Parameters

ParameterTypeDescription
$exceptionThrowableException to render and convert to a Response object.

Returns

Response: Object containing the rendered exception output.

Throws