summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEtienne Kneuss <colder@php.net>2008-03-08 22:12:32 +0000
committerEtienne Kneuss <colder@php.net>2008-03-08 22:12:32 +0000
commite9a6f0f24a1f8381e38fa4f16cfb27f04525527d (patch)
treee22b95da00ab4dbaa2a92c00af486b4fb63848e4
parentfd0d44f0a78bf528cc780b1fd5036e390de19a22 (diff)
downloadphp-git-e9a6f0f24a1f8381e38fa4f16cfb27f04525527d.tar.gz
MFH: User error handlers no longer catch supressed errors
-rw-r--r--ext/standard/tests/general_functions/bug44295.phpt26
-rw-r--r--main/main.c27
-rw-r--r--main/php.h7
-rw-r--r--main/php_globals.h2
4 files changed, 40 insertions, 22 deletions
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--
+<?php if (!extension_loaded("spl") || is_dir('/this/path/does/not/exist')) die("skip"); ?>
+--FILE--
+<?php
+$dir = '/this/path/does/not/exist';
+
+set_error_handler('my_error_handler');
+function my_error_handler() {$a = func_get_args(); print "in error handler\n"; }
+
+try {
+ print "before\n";
+ $iter = new DirectoryIterator($dir);
+ print get_class($iter) . "\n";
+ print "after\n";
+} catch (Exception $e) {
+ print "in catch: ".$e->getMessage()."\n";
+}
+?>
+==DONE==
+<?php exit(0); ?>
+--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;