-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathError.php
43 lines (39 loc) · 1.03 KB
/
Error.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace core;
/**
* Temporarily disable the error handler.
* Useful when calling legacy code and you don't want the
* new code to get written as sloppy as the old because of
* missing strictness.
*/
class Error
{
private static $handler = null;
private static $handlex = null;
public static function mute()
{
if (self::$handler !== null) {
throw new \Exception("Already muted, deverr calling it twice");
}
self::$handler = set_error_handler(function ($errno, $errstr, $errfile, $errline) {
//error_log("Error::mute ($errfile:$errline) $errno: $errstr";);
return true;
});
self::$handlex = set_exception_handler(function ($e) {
return true;
});
return self::$handler;
}
public static function unmute()
{
if (self::$handler === null) {
throw new \Exception("Already unmuted, deverr calling it without setting");
}
$handler = self::$handler;
$handlex = self::$handlex;
self::$handler = null;
self::$handlex = null;
set_exception_handler($handlex);
return set_error_handler($handler);
}
}