Skip to content

Commit 10b49c4

Browse files
authored
Create get-backtrace-of-warning.php
1 parent 77fc2c4 commit 10b49c4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
// Log the backtrace of a warning instead of just the first line.
3+
4+
class WarningWithStacktrace extends ErrorException {}
5+
set_error_handler(function($severity, $message, $file, $line) {
6+
if ((error_reporting() & $severity)) {
7+
if ($severity & (E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE | E_DEPRECATED)) {
8+
$ex = new WarningWithStacktrace($message, 0, $severity, $file, $line);
9+
error_log($ex);
10+
return true;
11+
} else {
12+
throw new ErrorException($message, 0, $severity, $file, $line);
13+
}
14+
}
15+
});

0 commit comments

Comments
 (0)