1
<?php
2
3
class ErrorHandler {
4
static $callbacks = array();
5
6
static function _errorHandler($errno, $errstr, $errfile, $errline) {
7
var_dump('errorHandler:');
8
foreach ( self::$callbacks as $callback ) {
9
call_user_func($callback, $errno, $errstr, $errfile, $errline);
10
}
11
}
12
}
13
14
function myErrorHandler($errno, $errstr, $errfile, $errline)
15
{
16
var_dump('myErrorHandler:'.$errstr."\n");
17
}
18
19
$error_handler = 'ErrorHandler::_errorHandler';
20
// first set
21
set_error_handler($error_handler);
22
23
// make set_error_handler useless
24
aop_add_before('set_error_handler()',function($jp){
25
$args = $jp->getArguments();
26
ErrorHandler::$callbacks[] = $args[0];
27
$jp->setArguments(array($GLOBALS['error_handler']));
28
});
29
30
// other user set
31
set_error_handler('myErrorHandler');
32
33
// trigger error
34
mysql_connect();
35
36
trigger_error("log(x) for x <= 0 is undefined, you used: scale = $scale", E_USER_ERROR);
37
trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING);
38
trigger_error("Value at position $pos is not a number, using 0 (zero)", E_USER_NOTICE);