Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<Yaf_Dispatcher::setDefaultModuleYaf_Dispatcher::setRequest>
^Yaf_DispatcherLast updated: Mon, 26 Oct 2026

Yaf_Dispatcher::setErrorHandler

(Yaf >=1.0.0)

Yaf_Dispatcher::setErrorHandler — Set error handler

Description

public function Yaf_Dispatcher::setErrorHandler(mixed $callback, int $error_types = 0): Yaf_Dispatcher|null|false

Set an error handler for Yaf. When application.dispatcher.throwException is off, Yaf triggers catchable errors when unexpected errors occur.

This method is a wrapper of set_error_handler(); the handler is called whenever such an error is raised.

Parameters

callback

A callable callback, with the same semantics as the callback passed to set_error_handler().

error_types

The error types to handle, same as the error_levels parameter of set_error_handler(). Defaults to handling all error types.

Return Values

Returns the Yaf_Dispatcher object itself on success, false if calling set_error_handler() failed, or null if the application is not initialized.

Examples

Example #1 Yaf_Dispatcher::setErrorHandler() example

<?php
$app = new Yaf_Application(dirname(__FILE__) . "/conf/application.ini");

Yaf_Dispatcher::getInstance()->setErrorHandler(function ($errno, $errstr) {
    // Route errors to ErrorController::errorAction
    $request = Yaf_Dispatcher::getInstance()->getRequest();
    $request->setControllerName("Error");
    $request->setActionName("error");
});

$app->run();
?>

See Also


<Yaf_Dispatcher::setDefaultModuleYaf_Dispatcher::setRequest>
^Yaf_DispatcherLast updated: Mon, 26 Oct 2026