/** * Build and return a human-readable backtrace message * * @return string containing the backtrace /**/ function build_backtrace($errno = null, $errstr = null, $errfile = null, $errline = null, $vars = null) { global $_DEBUG; // Generate an error message that can be emailed to the administrator $bt = ' datetime: ' . date('Y-m-d H:i:s (T)') . "\n"; if ($errno) { $bt .= ' errornum: ' . $errno . "\n" . ' error type: ' . error_type($errno) . "\n" . 'error string: ' . $errstr . "\n" . ' filename: ' . $errfile . "\n" . ' error line: ' . $errline . "\n"; } // Print a backtrace $bt .= "\n==========================================================================\n\n" . "Backtrace: \n\n"; $backtrace = debug_backtrace(); array_shift($backtrace); if ($backtrace[0]['function'] == 'error_handler') { array_shift($backtrace); } foreach ($backtrace as $layer) { foreach (array('file', 'line', 'class', 'function', 'type', 'args') as $key) { $val = $layer[$key]; $bt .= str_repeat(' ', max(8 - strlen($key), 0)) . "{$key}: "; if (is_array($val) || is_object($val)) { $bt .= print_r($val, true); } else { $bt .= "{$val}\n"; } } $bt .= "\n"; } // Print out the global $_DEBUG, as it's going to be a handy thing to have if (!empty($_DEBUG)) { $bt .= "\n==========================================================================\n\n" . '$_DEBUG: ' . print_r($_DEBUG, true); } // Print out some global stuff since we can't print out all of the variables if (!empty($_GET)) { $bt .= "\n==========================================================================\n\n" . '$_GET: ' . print_r($_GET, true); } if (!empty($_POST)) { $bt .= "\n==========================================================================\n\n" . '$_POST: ' . print_r($_POST, true); } // And dump the current user info if (!empty($_SESSION)) { $bt .= "\n==========================================================================\n\n" . '$_SESSION: ' . print_r($_SESSION, true); } if (!empty($_SERVER)) { $bt .= "\n==========================================================================\n\n" . '$_SERVER: ' . print_r($_SERVER, true); } $constant_list = get_defined_constants(true); ksort($constant_list['user']); if (!empty($constant_list)) { $bt .= "\n==========================================================================\n\n" . '$constant_list["user"]: '******'user'], true); } ### stupid recursive objects break non-cutting-edge versions of php #$bt .= "\n==========================================================================\n\n" # ."vars:\n" # .print_r($vars, true); // Cleanup $bt = preg_replace('/Array\\s+\\(\\s+\\)\\n+/', "Array ( )\n", $bt); $bt .= "\n\n"; // Return return $bt; }
<?php if (option('env') > ENV_PRODUCTION && option('debug')) { ?> <?php if (!$is_http_error) { ?> <p>[<?php echo error_type($errno); ?> ] <?php echo $errstr; ?> (in <strong><?php echo $errfile; ?> </strong> line <strong><?php echo $errline; ?> </strong>) </p> <?php } ?> <?php if ($debug_args = set('_lim_err_debug_args')) { ?> <p><strong>Debug arguments</strong></p> <pre><code><?php
<?php if (!empty($notices)) { ?> <div class="lim-debug lim-notices"> <h4> → Notices and warnings</h4> <dl> <?php $cpt = 1; foreach ($notices as $notice) { ?> <dt>[<?php echo $cpt . '. ' . error_type($notice['errno']); ?> ]</dt> <dd> <?php echo $notice['errstr']; ?> in <strong><code><?php echo $notice['errfile']; ?> </code></strong> line <strong><code><?php echo $notice['errline']; ?> </code></strong> </dd> <?php $cpt++; }
/** * Default error handler * * @param string $errno * @param string $errstr * @param string $errfile * @param string $errline * @return string error output */ function error_default_handler($errno, $errstr, $errfile, $errline) { $is_http_err = http_response_status_is_valid($errno); $http_error_code = $is_http_err ? $errno : SERVER_ERROR; status($http_error_code); if (($errno == E_USER_NOTICE || $errno == E_NOTICE) && option('debug')) { $o = "<p>[" . error_type($errno) . "] "; $o .= "{$errstr} in <strong>{$errfile}</strong> line <strong>{$errline}</strong>: "; $o .= "</p>"; error_notice($o); return; } return $http_error_code == NOT_FOUND ? error_not_found_output($errno, $errstr, $errfile, $errline) : error_server_error_output($errno, $errstr, $errfile, $errline); }
return 'E_COMPILE_WARNING'; case E_USER_ERROR: // 256 // return 'E_USER_ERROR'; case E_USER_WARNING: // 512 // return 'E_USER_WARNING'; case E_USER_NOTICE: // 1024 // return 'E_USER_NOTICE'; case E_STRICT: // 2048 // return 'E_STRICT'; case E_RECOVERABLE_ERROR: // 4096 // return 'E_RECOVERABLE_ERROR'; case E_DEPRECATED: // 8192 // return 'E_DEPRECATED'; case E_USER_DEPRECATED: // 16384 // return 'E_USER_DEPRECATED'; } return ""; } set_exception_handler(function (Exception $e) { error_log(sprintf('Вызвана ошибка %d: %s; %s', $e->getCode(), $e->getMessage(), $e->getTraceAsString())); }); set_error_handler(function ($errno, $errstr, $errfile, $errline, array $errcontext) { error_log(sprintf('[%s]: %s in %s at %d line', error_type($errno), $errstr, $errfile, $errline)); });
public final function limit_top($limittime = 120) { global $_K; if ($_K['keyword_top'] > 0) { $topaction = get_line_top(); $accesstime = time() - $topaction[1]; if ($topaction[0] != $_K['keyword_top']) { $this->error('激活该关键词之前,您要先' . error_type($_K['keyword_top'])); } } return true; }
/** * Returns notices output rendering and reset notices * * @return string */ function error_notices_render() { if (option('debug') && option('env') > ENV_PRODUCTION) { $notices = error_notice(); error_notice(null); // reset notices if (empty($notices)) { return ''; } ob_start(); ?> <div class="lim-debug lim-notices"> <h4> → Notices and warnings</h4> <dl> <?php $cpt = 1; foreach ($notices as $notice) { ?> <dt>[<?php echo $cpt . '. ' . error_type($notice['errno']); ?> ]</dt> <dd> <?php echo $notice['errstr']; ?> in <strong><code><?php echo $notice['errfile']; ?> </code></strong> line <strong><code><?php echo $notice['errline']; ?> </code></strong> </dd> <?php $cpt++; } ?> </dl> <hr> </div> <?php return ob_get_clean(); } }