Asf_Application::setErrorHandler

(Asf >= 2.2.1)

PHP脚本执行异常预警


Description

public bool Asf_Application::setErrorHandler(callable $error_handler)

Parameters

error_handler

First of all turn on asf.dispathcer.log.err = 1

Accept the function name, an array containing an object reference and a method name can also be supplied

Return Values

设置成功返回 true, 否则会有异常信息提示

Examples

Example #1

<?php
// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
}

$handle = new Asf\Application($configs);
$handle->setErrorHandler('myErrorHandler');
$handle->run();

Example #2

<?php
// error handler function
class Debug
{
    public static function myErrorHandler($errno, $errstr, $errfile, $errline)
    {
    }
}

$handle = new Asf\Application($configs);
$handle->setErrorHandler(array('Debug', 'myErrorHandler'));
$handle->run();

Example #3

<?php
// error handler function
class Debug
{
    public function myErrorHandler($errno, $errstr, $errfile, $errline)
    {
    }
}

$handler = new Debug();

$handle = new Asf\Application($configs);
$handle->setErrorHandler(array($handler, 'myErrorHandler'));
$handle->run();

Example #4

<?php
class Bootstrap
{
    public function __initAlarm()
    {
        $app = Asf\Application::getInstance();
        $app->setErrorHandler(array($this, 'alarm'));
    }

    public function alarm($errno, $errstr, $errfile, $errline)
    {
    }
}

$handle = new Asf\Application($configs);
$handle->bootstrap()->run();