From: Etienne Kneuss Date: Sat, 8 Mar 2008 22:12:32 +0000 (+0000) Subject: MFH: User error handlers no longer catch supressed errors X-Git-Tag: BEFORE_NEW_PARAMETER_PARSE~653 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e9a6f0f24a1f8381e38fa4f16cfb27f04525527d;p=php MFH: User error handlers no longer catch supressed errors --- diff --git a/ext/standard/tests/general_functions/bug44295.phpt b/ext/standard/tests/general_functions/bug44295.phpt new file mode 100644 index 0000000000..9c12719912 --- /dev/null +++ b/ext/standard/tests/general_functions/bug44295.phpt @@ -0,0 +1,26 @@ +--TEST-- +user defined error handler + set_error_handling(EH_THROW) +--SKIPIF-- + +--FILE-- +getMessage()."\n"; +} +?> +==DONE== + +--EXPECT-- +before +in catch: DirectoryIterator::__construct(/this/path/does/not/exist): failed to open dir: No such file or directory +==DONE== diff --git a/main/main.c b/main/main.c index 2cf47034ff..7098a9aaeb 100644 --- a/main/main.c +++ b/main/main.c @@ -778,17 +778,15 @@ PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC) /* {{{ 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; + EG(error_handling) = error_handling; + EG(exception_class) = exception_class; + + if (error_handling == EH_NORMAL) { + EG(user_error_handler) = EG(user_error_handler_old); + } else { + EG(user_error_handler_old) = EG(user_error_handler); + EG(user_error_handler) = NULL; } - PG(last_error_lineno) = 0; } /* }}} */ @@ -833,7 +831,7 @@ static void php_error_cb(int type, const char *error_filename, const uint error_ } /* according to error handling mode, suppress error, throw exception or show it */ - if (PG(error_handling) != EH_NORMAL) { + if (EG(error_handling) != EH_NORMAL) { switch (type) { case E_ERROR: case E_CORE_ERROR: @@ -854,8 +852,8 @@ static void php_error_cb(int type, const char *error_filename, const uint error_ /* 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); + if (EG(error_handling) == EH_THROW && !EG(exception)) { + zend_throw_error_exception(EG(exception_class), buffer, 0, type TSRMLS_CC); } efree(buffer); return; @@ -1729,7 +1727,8 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod PG(last_error_message) = NULL; PG(last_error_file) = NULL; PG(last_error_lineno) = 0; - PG(error_handling) = EH_NORMAL; + EG(error_handling) = EH_NORMAL; + EG(exception_class) = NULL; PG(disable_functions) = NULL; PG(disable_classes) = NULL; diff --git a/main/php.h b/main/php.h index 65dd2419fe..5c51d86f66 100644 --- a/main/php.h +++ b/main/php.h @@ -278,12 +278,7 @@ int cfgparse(void); END_EXTERN_C() #define php_error zend_error - -typedef enum { - EH_NORMAL = 0, - EH_SUPPRESS, - EH_THROW -} error_handling_t; +#define error_handling_t zend_error_handling_t BEGIN_EXTERN_C() PHPAPI void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class TSRMLS_DC); diff --git a/main/php_globals.h b/main/php_globals.h index efed5f7cf0..fec2e94bfd 100644 --- a/main/php_globals.h +++ b/main/php_globals.h @@ -150,8 +150,6 @@ struct _php_core_globals { char *last_error_message; char *last_error_file; int last_error_lineno; - error_handling_t error_handling; - zend_class_entry *exception_class; char *disable_functions; char *disable_classes;