int is_function = 0; /* get error text into buffer and escape for html if necessary */ buffer_len = vspprintf(&buffer, 0, format, args); if (PG(html_errors)) { int len; char *replace = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC); efree(buffer); buffer = replace; buffer_len = len; } /* which function caused the problem if any at all */ if (php_during_module_startup()) { function = \ } else if (php_during_module_shutdown()) { function = \ } else if (EG(current_execute_data) && EG(current_execute_data)->opline && EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL ) { switch (EG(current_execute_data)->opline->op2.u.constant.value.lval) { case ZEND_EVAL: function = \ is_function = 1; break; case ZEND_INCLUDE: function = \ is_function = 1; break; case ZEND_INCLUDE_ONCE: function = \ is_function = 1; break; case ZEND_REQUIRE: function = \ is_function = 1; break; case ZEND_REQUIRE_ONCE: function = \ is_function = 1; break; default: function = \ } } else { function = get_active_function_name(TSRMLS_C); if (!function || !strlen(function)) { function = \ } else { is_function = 1; } } if (is_function) { origin_len = spprintf(&origin, 0, \
} else { origin_len = spprintf(&origin, 0, \ } if (PG(html_errors)) { int len; char *replace = php_escape_html_entities(origin, origin_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC); efree(origin); origin = replace; } if (docref && docref[0] == '#') { docref_target = strchr(docref, '#'); docref = NULL; } if (!docref && is_function) { if (space[0] == '\\0') { spprintf(&docref_buf, 0, \ } else { spprintf(&docref_buf, 0, \ } while((p = strchr(docref_buf, '_')) != NULL) { *p = '-'; } docref = docref_buf; } if (docref && is_function && (PG(html_errors) || strlen(PG(docref_root)))) { if (strncmp(docref, \ /* We don't have 'http://' so we use docref_root */ char *ref; /* temp copy for duplicated docref */ docref_root = PG(docref_root); ref = estrdup(docref); if (docref_buf) { efree(docref_buf); } docref_buf = ref; /* strip of the target if any */ p = strrchr(ref, '#'); if (p) { target = estrdup(p); if (target) { docref_target = target; *p = '\\0'; } } /* add the extension if it is set in ini */ if (PG(docref_ext) && strlen(PG(docref_ext))) { spprintf(&docref_buf, 0, \ efree(ref); } docref = docref_buf; } /* display html formatted or only show the additional links */ if (PG(html_errors)) { spprintf(&message, 0, \[%s]: %s\origin, docref_root, docref,
docref_target, docref, buffer); } else { spprintf(&message, 0, \ } if (target) { efree(target); } } else { spprintf(&message, 0, \ } efree(origin); if (docref_buf) { efree(docref_buf); } if (PG(track_errors) && module_initialized && EG(active_symbol_table) && (!EG(user_error_handler) || !(EG(user_error_handler_error_reporting) & type))) { zval *tmp; ALLOC_INIT_ZVAL(tmp); ZVAL_STRINGL(tmp, buffer, buffer_len, 1); zend_hash_update(EG(active_symbol_table), \sizeof(zval *), NULL); } efree(buffer); php_error(type, \ efree(message); }
/* }}} */
/* {{{ php_error_docref0 */
/* See: CODING_STANDARDS for details. */
PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...) { va_list args; va_start(args, format); php_verror(docref, \ va_end(args); }
/* }}} */
/* {{{ php_error_docref1 */
/* See: CODING_STANDARDS for details. */
PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...) { va_list args; va_start(args, format); php_verror(docref, param1, type, format, args TSRMLS_CC); va_end(args); }
/* }}} */
/* {{{ php_error_docref2 */
/* See: CODING_STANDARDS for details. */
PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...) { char *params;
va_list args; spprintf(¶ms, 0, \ va_start(args, format); php_verror(docref, params ? params : \ va_end(args); if (params) { efree(params); } }
/* }}} */
/* {{{ php_html_puts */
PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC) { zend_html_puts(str, size TSRMLS_CC); }
/* }}} */
/* {{{ php_suppress_errors */
PHPAPI void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class TSRMLS_DC) { PG(error_handling) = error_handling; PG(exception_class) = exception_class; if (PG(last_error_message)) { free(PG(last_error_message)); PG(last_error_message) = NULL; } if (PG(last_error_file)) { free(PG(last_error_file)); PG(last_error_file) = NULL; } PG(last_error_lineno) = 0; }
/* }}} */
/* {{{ php_error_cb
extended error handling function */
static void php_error_cb(int type, const char *error_, const uint error_lineno, const char *format, va_list args) { char *buffer; int buffer_len, display; TSRMLS_FETCH(); buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args); /* check for repeated errors to be ignored */ if (PG(ignore_repeated_errors) && PG(last_error_message)) { /* no check for PG(last_error_file) is needed since it cannot * be NULL if PG(last_error_message) is not NULL */ if (strcmp(PG(last_error_message), buffer) || (!PG(ignore_repeated_source) && ((PG(last_error_lineno) != (int)error_lineno) || strcmp(PG(last_error_file), error_)))) { display = 1; } else { display = 0; } } else {
display = 1; }
/* store the error if it has changed */ if (display) { if (PG(last_error_message)) { free(PG(last_error_message)); } if (PG(last_error_file)) { free(PG(last_error_file)); } PG(last_error_type) = type; PG(last_error_message) = strdup(buffer); PG(last_error_file) = strdup(error_); PG(last_error_lineno) = error_lineno; }
/* according to error handling mode, suppress error, throw exception or show it */ if (PG(error_handling) != EH_NORMAL) { switch (type) { case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: case E_PARSE: /* fatal errors are real errors and cannot be made exceptions */ break; case E_STRICT: /* for the sake of BC to old damaged code */ break; case E_NOTICE: case E_USER_NOTICE: /* notices are no errors and are not treated as such like E_WARNINGS */ break; default: /* throw an exception if we are in EH_THROW mode * but DO NOT overwrite a pending exception */ if (PG(error_handling) == EH_THROW && !EG(exception)) { zend_throw_error_exception(PG(exception_class), buffer, 0, type TSRMLS_CC); } efree(buffer); return; } }
/* display/log the error if necessary */
if (display && (EG(error_reporting) & type || (type & E_CORE)) && (PG(log_errors) || PG(display_errors) || (!module_initialized))) { char *error_type_str; switch (type) { case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: error_type_str = \ break;
相关推荐: