/** * @brief Generates a user-level error/warning/notice message * * @param string $error_msg The designated error message for this error. * @param string $error_type The designated error type for this error.It * only works with the E_USER family of constants. */ public function error($error_msg, $error_type = E_USER_ERROR) { echo '<pre>'; debug_print_backtrace(); echo '</pre>'; trigger_error($error_msg, $error_type); }
function actionLink($action, $id = "", $args = "", $urlname = "") { global $boardroot, $mainPage; if ($boardroot == "") { $boardroot = "./"; } $bucket = "linkMangler"; include 'lib/pluginloader.php'; $res = ""; if ($action != $mainPage) { $res .= "&page={$action}"; } if ($id != "") { $res .= "&id=" . urlencode($id); } if ($args) { $res .= "&{$args}"; } if (strpos($res, "&")) { debug_print_backtrace(); Kill("Found &amp; in link"); } if ($res == "") { return $boardroot; } else { return $boardroot . "?" . substr($res, 1); } }
/** * 错误输出 * @param mixed $error 错误 * @return void */ function halt($error) { $e = array(); if (APP_DEBUG) { //调试模式下输出错误信息 if (!is_array($error)) { $trace = debug_backtrace(); $e['message'] = $error; $e['file'] = $trace[0]['file']; $e['line'] = $trace[0]['line']; ob_start(); debug_print_backtrace(); $e['trace'] = ob_get_clean(); } else { $e = $error; } } else { //否则定向到错误页面 $error_page = C('ERROR_PAGE'); if (!empty($error_page)) { redirect($error_page); } else { if (C('SHOW_ERROR_MSG')) { $e['message'] = is_array($error) ? $error['message'] : $error; } else { $e['message'] = C('ERROR_MESSAGE'); } } } // 包含异常页面模板 include C('TMPL_EXCEPTION_FILE'); exit; }
/** * 致命错误 * 程序执行完后执行的操作,有些级别的错误self::appError是捕捉不到的 * @return void */ public static function fatalError() { // error_get_last() 函数获取最后发生的错误。 // 该函数以数组的形式返回最后发生的错误。 // 返回的数组包含 4 个键和值: // [type] - 错误类型 // [message] - 错误消息 // [file] - 发生错误所在的文件 // [line] - 发生错误所在的行 if ($errorArray = error_get_last()) { switch ($errorArray['type']) { case E_ERROR: case E_PARSE: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: ob_end_clean(); // 致命的错误,要停止运行,清除以前的所有输出 ob_start(); // 开启缓冲区 debug_print_backtrace(); // 输出调试信息 $errorArray['trace'] = ob_get_clean(); // 获取刚输出到缓冲区的调试信息 include dirname(__DIR__) . '/Views/fatalError.php'; break; } } }
function __autoload($class_name) { static $files = null; $success = false; $class_file = strtolower($class_name) . '.php'; if (empty($files)) { $files = array(); $glob = glob(MICROSITE_PATH . '/microsite/classes/*.php'); $fnames = array_map(create_function('$a', 'return strtolower(basename($a));'), $glob); $files = array_merge($files, array_combine($fnames, $glob)); $glob = glob(MICROSITE_PATH . '/microsite/controllers/*.php'); $fnames = array_map(create_function('$a', 'return strtolower(basename($a, ".php") . "controller.php");'), $glob); $files = array_merge($files, array_combine($fnames, $glob)); } // Search in the available files for the undefined class file. if (isset($files[$class_file])) { require $files[$class_file]; // If the class has a static method named __static(), execute it now, on initial load. if (class_exists($class_name, false) && method_exists($class_name, '__static')) { call_user_func(array($class_name, '__static')); } $success = true; } if (!$success) { var_dump($class_name); var_dump($files); debug_print_backtrace(); } }
function my_die($text) { echo '</select></p></div><div style="padding: 1em; color:red; font-size:120%; background-color:#CEECF5;">' . '<p><b>Fatal Error:</b> ' . tohtml($text) . "</p></div><hr /><pre>Backtrace:\n\n"; debug_print_backtrace(); echo '</pre><hr />'; die('</body></html>'); }
private function _preg_error() { switch (preg_last_error()) { case PREG_INTERNAL_ERROR: echo 'PREG_INTERNAL_ERROR'; break; case PREG_BACKTRACK_LIMIT_ERROR: echo 'PREG_BACKTRACK_LIMIT_ERROR'; break; case PREG_RECURSION_LIMIT_ERROR: echo 'PREG_RECURSION_LIMIT_ERROR'; break; case PREG_BAD_UTF8_ERROR: echo 'PREG_BAD_UTF8_ERROR'; break; // This is only valid for php > 5.3, not certain how to code around it for unit tests // case PREG_BAD_UTF8_OFFSET_ERROR: echo('PREG_BAD_UTF8_OFFSET_ERROR'); break; // This is only valid for php > 5.3, not certain how to code around it for unit tests // case PREG_BAD_UTF8_OFFSET_ERROR: echo('PREG_BAD_UTF8_OFFSET_ERROR'); break; default: //die("Unknown preg error."); return; } echo "<hr><pre>"; debug_print_backtrace(); die; }
public function testRegistering() { $this->appMock->expects($this->at(0))->method('singleton')->will($this->returnCallback(function ($boundTo, $closure) { switch ($boundTo) { case BladedServiceProvider::PROVIDES_SERVICE: $this->assertTrue($closure($this->appMock) instanceof BladedManager); break; case IBladedManager::class: $this->assertTrue($closure($this->appMock) instanceof BladedManager); break; case BladedServiceProvider::PROVIDES_STRING_COMPILER: $this->assertTrue($closure($this->appMock) instanceof StringCompiler); break; default: var_dump($boundTo); die('dead: ' . debug_print_backtrace()); } })); $this->appMock->expects($this->any())->method('make')->will($this->returnCallback(function ($resolvable) { switch ($resolvable) { case 'files': return new Filesystem(); case 'blade.compiler': return $this->bladeCompilerMock; case 'path.storage': return __DIR__; default: var_dump($resolvable); die('dead'); } })); $this->assertNull($this->testInstance->registering()); }
public function assert($cond, $msg = 'Error', $params = array()) { // TODO: obtener un mensaje que diga mas, linea, clase y // metodo donde se intenta verificar la condicion //if (!$cond) $this->suite->report('error'); if (!$cond) { // http://php.net/manual/en/function.debug-backtrace.php ob_start(); debug_print_backtrace(); // Stack de llamadas que resultaron en un test que falla $trace = ob_get_contents(); // Trace es lo mismo que moreInfo pero abajo se procesa para mostrar solo el trace que importa. $moreInfo = ob_get_contents(); // Todos los echos y prints que se pudieron hacer ob_end_clean(); // Se quita la llamada a este metodo de el stack (assert) $pos = strpos($trace, "\n#1 "); if ($pos !== false) { $trace = substr($trace, $pos); } // TODO: hay que remover las ultimas lineas que son llamadas del framework /* * #4 CoreController->testAppAction(Array ()) called at [C:\wamp\www\YuppPHPFramework\core\mvc\core.mvc.YuppController.class.php:59] #5 YuppController->__call(testApp, Array ()) #6 CoreController->testApp() called at [C:\wamp\www\YuppPHPFramework\core\routing\core.routing.Executer.class.php:163] #7 Executer->execute() called at [C:\wamp\www\YuppPHPFramework\core\web\core.web.RequestManager.class.php:158] #8 RequestManager::doRequest() called at [C:\wamp\www\YuppPHPFramework\index.php:94] */ $this->suite->report(get_class($this), 'ERROR', $msg, $trace, $moreInfo, $params); } else { // tengo que mostrar los tests correctos $this->suite->report(get_class($this), 'OK', $msg); } }
function d($a) { print "<pre>"; var_dump($a); debug_print_backtrace(0, 3); die; }
public static function handlerAsserts($file, $line, $code) { echo "<hr>Echec de l'assertion :\r\n\t\t\tFile '{$file}'<br />\r\n\t\t\tLine '{$line}'<br />\r\n\t\t\tCode '{$code}'<br /><hr />"; echo "<pre>"; debug_print_backtrace(); echo "</pre>"; }
/** * @throws Exception */ public function testValue($value) { if (!is_a($value, $this->typeOf)) { debug_print_backtrace(); throw new \Exception('Element is not an instance of: ' . $this->typeOf); } }
public function __construct($name, $type, $file) { if (DEBUG) { debug_print_backtrace(); } trigger_error(sprintf("File '%s' requires %s '%s', which is not available.", $file, $type, $name), E_USER_ERROR); }
public function run() { foreach ($this->testCases as $testCase) { try { $testCase->run(); } catch (Exception $e) { ob_start(); debug_print_backtrace(); // Stack de llamadas que resultaron en un test que falla $trace = ob_get_contents(); $moreInfo = ob_get_contents(); // Todos los echos y prints que se pudieron hacer ob_end_clean(); // Se quita la llamada a este metodo de el stack (assert) $pos = strpos($trace, "\n"); if ($pos !== false) { $trace = substr($trace, $pos); } // TODO: hay que remover las ultimas lineas que son llamadas del framework /* * #4 CoreController->testAppAction(Array ()) called at [C:\wamp\www\YuppPHPFramework\core\mvc\core.mvc.YuppController.class.php:59] #5 YuppController->__call(testApp, Array ()) #6 CoreController->testApp() called at [C:\wamp\www\YuppPHPFramework\core\routing\core.routing.Executer.class.php:163] #7 Executer->execute() called at [C:\wamp\www\YuppPHPFramework\core\web\core.web.RequestManager.class.php:158] #8 RequestManager::doRequest() called at [C:\wamp\www\YuppPHPFramework\index.php:94] */ $this->report(get_class($testCase), 'EXCEPTION', $e->getMessage(), $trace, $moreInfo); } } }
function query($req) { // Si c'est la première requête if ($this->reqcount == 0) { // on ititialise les paramètres $this->initParams(); } // On incrémente le compteur de requêtes $this->reqcount++; // Si la requête n'arrive pas à s'exécuter if (!($res = parent::query($req))) { // On commencer à mettre la sortie dans un buffer (ob = output buffer) ob_start(); // On affiche l'état de la pile d'appel (pour savoir pourquoi ça plante, d'uù le script est lancé) debug_print_backtrace(); // On écrit tout ça dans un fichier de logs "mysql_errors" avec la date, l'erreur, la requête SQL associée et l'état de la pile d'appel dans le buffer file_put_contents(FONCTIONS . "mysql_errors", date('[d/m/Y - H:i:s]') . ' Erreur MySQL : ' . $this->error . ' pendant la requête ' . $req . ' Backtrace: ' . ob_get_contents()); // On termine la capture de la sortie et on efface ce qu'on a enregistré ob_end_clean(); // Et on termine le script. die("Une erreur s'est produite: " . $this->error); } // Sinon, tout va bien, on renvoie le résultat. return $res; }
private function categories2xml($categories) { foreach ($categories as $category) { if (!is_object($category)) { echo "not an object\n"; var_dump($category); debug_print_backtrace(); die; } if (isset($category->id)) { echo "<category oldid='{$category->id}' "; } if (isset($category->idnumber) && !empty($category->idnumber)) { echo "idnumber='{$category->idnumber}' "; } if (isset($category->id)) { $name = str_replace(array("&", "<", ">", '"', "'"), array("&", "<", ">", """, "'"), $category->name); echo "name='{$name}'>"; } if (property_exists($category, 'categories')) { foreach ($category->categories as $categories2) { $this->categories2xml(array($categories2)); } } if (isset($category->id)) { echo "</category>\n"; } } }
/** * Apresenta os erros do PHP ao desenvolvedor * @param integer $codigo * @param string $mensagem * @param string $arquivo * @param integer $linha * @param string $tipoErro * @return void */ function reportarErro($codigo, $mensagem, $arquivo, $linha, $tipoErro) { if (strpos($arquivo, 'conexaoPadrao')) { return; } $imagemErro = 'erro.png'; switch ($codigo) { case E_NOTICE: $tipoErro = 'Notice'; $imagemErro = 'notice.png'; break; case E_WARNING: $tipoErro = 'Warning'; break; case E_PARSE: $tipoErro = 'Parser'; break; case E_COMPILE_ERROR: $tipoErro = 'Fatal'; break; } if (preg_match('/(.*)\\.html\\.php(.*)/', $arquivo, $resultado)) { $mensagem = str_replace('Undefined index:', 'Variável não registrada no controle para apresentação no template: ', $mensagem); $back = null; } else { ob_start(); debug_print_backtrace(); $back = ob_get_clean(); } echo "\n\t\t<link type='text/css' rel='stylesheet' href='.sistema/debug.css' />\n\t\t<fieldset class='erroNegro'>\n\t\t\t<legend>{$tipoErro}</legend>\n\t\t\t<img src='.sistema/imagens/{$imagemErro}' alt='[imagem]'>\n\t\t\t<table summary='text' class='erroNegro'>\n\t\t\t\t<tr>\n\t\t\t\t\t<td>Mensagem:</td>\n\t\t\t\t\t<td><b>{$mensagem}</b></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td>Arquivo:</td>\n\t\t\t\t\t<td>## {$arquivo}({$linha})</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t<pre>{$back}\n\t\t</pre>\n\t\t</fieldset>"; }
/** * Handle an error with the most basic handler on the CLI * * @return string */ public function handle() { // If this is a reqular exception, always quit, else check the type if (!$this->exception instanceof \ErrorException) { $this->quit = true; } else { // Only quit after specific error types switch ($this->exception->getSeverity()) { case E_ERROR: case E_CORE_ERROR: case E_USER_ERROR: $this->quit = true; } } if ($this->exception instanceof \ErrorException) { $error_type = \Skeleton\Error\Util\Misc::translate_error_code($this->exception->getSeverity()); } else { $error_type = 'Exception'; } $output = "\n"; $output .= 'Error: ' . $this->exception->getMessage() . "\n"; $output .= 'Type: ' . $error_type . "\n"; $output .= 'File: ' . $this->exception->getFile() . "\n"; $output .= 'Line: ' . $this->exception->getLine() . "\n"; $output .= 'Time: ' . date('Y-m-d H:i:s') . "\n"; if (!$this->exception instanceof \ErrorException) { ob_start(); debug_print_backtrace(); $backtrace = ob_get_clean(); $output .= "\n"; $output .= $backtrace . "\n"; } return $output; }
function print_stack_trace() { ob_start(); debug_print_backtrace(); $data = ob_get_clean(); error_log($data); }
function wc1c_error($message, $type = "Error", $no_exit = false) { global $wc1c_is_error; $wc1c_is_error = true; $message = "{$type}: {$message}"; $last_char = substr($message, -1); if (!in_array($last_char, array('.', '!', '?'))) { $message .= '.'; } error_log($message); echo "{$message}\n"; if (wc1c_is_debug()) { echo "\n"; debug_print_backtrace(); $info = array("Request URI" => wc1c_full_request_uri(), "Server API" => PHP_SAPI, "Memory limit" => ini_get('memory_limit'), "Maximum POST size" => ini_get('post_max_size'), "PHP version" => PHP_VERSION, "WordPress version" => get_bloginfo('version'), "Plugin version" => WC1C_VERSION); echo "\n"; foreach ($info as $info_name => $info_value) { echo "{$info_name}: {$info_value}\n"; } } if (!$no_exit) { wc1c_wpdb_end(); exit; } }
function my_error_handler($e_number, $e_message, $e_file, $e_line, $e_vars) { // Build the error message: $message = "An error occurred in script '{$e_file}' on line {$e_line}: {$e_message}\n"; // Add the date and time: $message .= "Date/Time: " . date('n-j-Y H:i:s') . "\n"; if (!LIVE) { // Development (print the error). // Show the error message: echo '<div class="error">' . nl2br($message); // Add the variables and a backtrace: echo '<pre>' . print_r($e_vars, 1) . "\n"; debug_print_backtrace(); echo '</pre></div>'; } else { // Don't show the error: // Send an email to the admin: $body = $message . "\n" . print_r($e_vars, 1); mail(EMAIL, 'Site Error!', $body, 'From: email@example.com'); // Only print an error message if the error isn't a notice: if ($e_number != E_NOTICE) { echo '<div class="error">A system error occurred. We apologize for the inconvenience.</div><br />'; } } // End of !LIVE IF. }
public static function doit($params = []) { echo '<pre>'; debug_print_backtrace(); echo '</pre>'; exit; }
function get_backtrace() { ob_start(); debug_print_backtrace(); $str = ob_get_clean(); return $str; }
/** * Add info to a log file * * @param string $message Error message * @param integer $code Error code * @param string $backtrace Stack trace OPTIONAL * * @return void */ protected static function logInfo($message, $code, $backtrace = null) { if (!isset($backtrace) && 'cli' != PHP_SAPI) { ob_start(); if (defined('DEBUG_BACKTRACE_IGNORE_ARGS')) { debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); } else { debug_print_backtrace(); } $backtrace = ob_get_contents(); ob_end_clean(); } $message = date('[d-M-Y H:i:s]') . ' Error (code: ' . $code . '): ' . $message . PHP_EOL; // Add additional info $parts = array('Server API: ' . PHP_SAPI); if (!empty($_SERVER)) { if (isset($_SERVER['REQUEST_METHOD'])) { $parts[] = 'Request method: ' . $_SERVER['REQUEST_METHOD']; } if (isset($_SERVER['REQUEST_URI'])) { $parts[] = 'URI: ' . $_SERVER['REQUEST_URI']; } } $message .= implode(';' . PHP_EOL, $parts) . ';' . PHP_EOL; if ($backtrace && $code != static::ERROR_CLOSED) { $message .= 'Backtrace: ' . PHP_EOL . $backtrace . PHP_EOL . PHP_EOL; } \Includes\Utils\FileManager::write(static::getLogFile($code), $message, FILE_APPEND); }
public static function displayError($errorStr) { echo $errorStr; echo "Here you have the backtrace: <br><pre>"; debug_print_backtrace(); exit(1); }
function table4u_error($number, $msg, $file, $line, $vars) { echo '<pre>'; print_r(debug_print_backtrace()); echo '</pre>'; echo PHP_EOL; }
/** * @param object PEAR_Error object */ function displayFatalError($eobj) { $this->displayError($eobj); if (class_exists('PEAR_Config')) { $config =& PEAR_Config::singleton(); if ($config->get('verbose') > 5) { if (function_exists('debug_print_backtrace')) { debug_print_backtrace(); exit(1); } $raised = false; foreach (debug_backtrace() as $i => $frame) { if (!$raised) { if (isset($frame['class']) && strtolower($frame['class']) == 'pear' && strtolower($frame['function']) == 'raiseerror') { $raised = true; } else { continue; } } $frame['class'] = !isset($frame['class']) ? '' : $frame['class']; $frame['type'] = !isset($frame['type']) ? '' : $frame['type']; $frame['function'] = !isset($frame['function']) ? '' : $frame['function']; $frame['line'] = !isset($frame['line']) ? '' : $frame['line']; $this->_displayLine("#{$i}: {$frame['class']}{$frame['type']}{$frame['function']} {$frame['line']}"); } } } exit(1); }
/** * @static * @param $error * @param string $type * @return int */ public static function saveErrorInLog($error, $type = Core_ErrorHandler::ERROR) { $trace = ''; $file = ''; $message = ''; if ($type == self::ERROR && null != $error) { ob_start(); debug_print_backtrace(); $trace = ob_get_contents(); ob_end_clean(); $message = $error['message']; $file = $error['file'] . ':' . $error['line']; } elseif ($type == self::EXCEPTION) { $trace = $error->getTraceAsString(); $message = $error->getMessage(); $file = $error->getFile() . ':' . $error->getLine(); } if (isset($_SESSION)) { ob_start(); var_dump($_SESSION); $session = ob_get_clean(); } $errorLogMessage = PHP_EOL . '---------------------------' . PHP_EOL . date('d-m-Y H:i:s') . PHP_EOL . 'Error in ' . $file . PHP_EOL . PHP_EOL . 'Error Message :' . PHP_EOL . $message . PHP_EOL . PHP_EOL . 'Trace :' . PHP_EOL . $trace . PHP_EOL . PHP_EOL . 'SERVER :' . PHP_EOL . var_export($_SERVER, true) . PHP_EOL . 'POST :' . PHP_EOL . var_export($_POST, true) . PHP_EOL . 'GET :' . PHP_EOL . var_export($_GET, true) . PHP_EOL . 'COOKIE :' . PHP_EOL . var_export($_COOKIE, true) . PHP_EOL . 'SESSION :' . PHP_EOL . (isset($session) ? $session : 'Session not started!') . PHP_EOL . '---------------------------'; $logPath = realpath(APPLICATION_PATH . '/../') . self::PATH_TO_ERROR_LOG; if (APPLICATION_ENV == 'production') { mail(ERROR_REPORT_MAIL, ERROR_REPORT_SUBJECT, $errorLogMessage); } return file_put_contents($logPath, $errorLogMessage, FILE_APPEND | LOCK_EX); }
/** * Log fatal error to Mautic's logs and throw exception for the parent generic error page to catch * * @throws \Exception */ public function handleFatal() { $error = error_get_last(); if ($error !== null) { $name = $this->getErrorName($error['type']); $this->logger->error("{$name}: {$error['message']} - in file {$error['file']} - at line {$error['line']}"); if ($error['type'] === E_ERROR || $error['type'] === E_CORE_ERROR || $error['type'] === E_USER_ERROR) { defined('MAUTIC_OFFLINE') or define('MAUTIC_OFFLINE', 1); if (MAUTIC_ENV == 'dev') { $message = "<pre>{$error['message']} - in file {$error['file']} - at line {$error['line']}</pre>"; // Get a trace ob_start(); debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $trace = ob_get_contents(); ob_end_clean(); // Remove first item from backtrace as it's this function which // is redundant. $trace = preg_replace('/^#0\\s+' . __FUNCTION__ . "[^\n]*\n/", '', $trace, 1); // Renumber backtrace items. $trace = preg_replace('/^#(\\d+)/me', '\'#\' . ($1 - 1)', $trace); $submessage = "<pre>{$trace}</pre>"; } else { $message = 'The site is currently offline due to encountering an error. If the problem persists, please contact the system administrator.'; $submessage = 'System administrators, check server logs for errors.'; } include __DIR__ . '/../../../../offline.php'; } } }
function c() { debug_print_backtrace(0, 1); debug_print_backtrace(0, 2); debug_print_backtrace(0, 0); debug_print_backtrace(0, 4); }