1
|
|
|
<?php |
2
|
|
|
function format_backtrace($trace) { |
3
|
|
|
$rv = ""; |
4
|
|
|
$idx = 1; |
5
|
|
|
|
6
|
|
|
if (is_array($trace)) { |
7
|
|
|
foreach ($trace as $e) { |
8
|
|
|
if (isset($e["file"]) && isset($e["line"])) { |
9
|
|
|
$fmt_args = []; |
10
|
|
|
|
11
|
|
|
if (is_array($e["args"])) { |
12
|
|
|
foreach ($e["args"] as $a) { |
13
|
|
|
if (!is_object($a)) { |
14
|
|
|
array_push($fmt_args, $a); |
15
|
|
|
} else { |
16
|
|
|
array_push($fmt_args, "[".get_class($a)."]"); |
17
|
|
|
} |
18
|
|
|
} |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
$filename = str_replace(dirname(__DIR__)."/", "", $e["file"]); |
22
|
|
|
|
23
|
|
|
$rv .= sprintf("%d. %s(%s): %s(%s)\n", |
24
|
|
|
$idx, $filename, $e["line"], $e["function"], implode(", ", $fmt_args)); |
25
|
|
|
|
26
|
|
|
$idx++; |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
return $rv; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function ttrss_error_handler($errno, $errstr, $file, $line, $context) { |
|
|
|
|
35
|
|
|
if (error_reporting() == 0 || !$errno) { |
36
|
|
|
return false; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); |
40
|
|
|
|
41
|
|
|
$context = format_backtrace(debug_backtrace()); |
42
|
|
|
$errstr = truncate_middle($errstr, 16384, " (...) "); |
43
|
|
|
|
44
|
|
|
if (class_exists("Logger")) { |
45
|
|
|
return Logger::get()->log_error($errno, $errstr, $file, $line, $context); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function ttrss_fatal_handler() { |
50
|
|
|
global $last_query; |
51
|
|
|
|
52
|
|
|
$error = error_get_last(); |
53
|
|
|
|
54
|
|
|
if ($error !== null) { |
55
|
|
|
$errno = $error["type"]; |
56
|
|
|
$file = $error["file"]; |
57
|
|
|
$line = $error["line"]; |
58
|
|
|
$errstr = $error["message"]; |
59
|
|
|
|
60
|
|
|
if (!$errno) { |
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$context = format_backtrace(debug_backtrace()); |
65
|
|
|
|
66
|
|
|
$file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); |
67
|
|
|
|
68
|
|
|
if ($last_query) { |
69
|
|
|
$errstr .= " [Last query: $last_query]"; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (class_exists("Logger")) { |
73
|
|
|
return Logger::get()->log_error($errno, $errstr, $file, $line, $context); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return false; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
register_shutdown_function('ttrss_fatal_handler'); |
81
|
|
|
set_error_handler('ttrss_error_handler'); |
82
|
|
|
|
83
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.