Created
October 14, 2010 07:25
-
-
Save scribu/625769 to your computer and use it in GitHub Desktop.
Backtrace Errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Forked from: http://stackoverflow.com/questions/1159216/how-can-i-get-php-to-produce-a-backtrace-upon-errors/1159235#1159235 | |
function process_error_backtrace($errno, $errstr, $errfile, $errline) { | |
if(!(error_reporting() & $errno)) | |
return; | |
switch($errno) { | |
case E_WARNING : | |
case E_USER_WARNING : | |
case E_STRICT : | |
case E_NOTICE : | |
case E_DEPRECATED : | |
case E_USER_NOTICE : | |
$type = 'warning'; | |
$fatal = false; | |
break; | |
default : | |
$type = 'fatal error'; | |
$fatal = true; | |
break; | |
} | |
$trace = debug_backtrace(); | |
array_shift($trace); | |
if(php_sapi_name() == 'cli') { | |
echo 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n"; | |
foreach($trace as $item) | |
echo ' ' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()' . "\n"; | |
} else { | |
echo '<p class="error_backtrace">' . "\n"; | |
echo ' Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n"; | |
echo ' <ol>' . "\n"; | |
foreach($trace as $item) | |
echo ' <li>' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()</li>' . "\n"; | |
echo ' </ol>' . "\n"; | |
echo '</p>' . "\n"; | |
} | |
if(ini_get('log_errors')) { | |
$items = array(); | |
foreach($trace as $item) | |
$items[] = (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()'; | |
$message = 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ': ' . join(' | ', $items); | |
error_log($message); | |
} | |
flush(); | |
if($fatal) | |
exit(1); | |
} | |
set_error_handler('process_error_backtrace'); |
what directory does this file go in and how does it get called?
You can place this file in your wp-content/mu-plugins directory; create it if it doesn’t exist.
Taken from:
https://make.wordpress.org/core/handbook/testing/reporting-bugs/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What up son son,this is ur boy...YOU!