]> granicus.if.org Git - php/commitdiff
MFH: User error handlers no longer catch supressed errors
authorEtienne Kneuss <colder@php.net>
Sat, 8 Mar 2008 22:12:32 +0000 (22:12 +0000)
committerEtienne Kneuss <colder@php.net>
Sat, 8 Mar 2008 22:12:32 +0000 (22:12 +0000)
ext/standard/tests/general_functions/bug44295.phpt [new file with mode: 0644]
main/main.c
main/php.h
main/php_globals.h

diff --git a/ext/standard/tests/general_functions/bug44295.phpt b/ext/standard/tests/general_functions/bug44295.phpt
new file mode 100644 (file)
index 0000000..9c12719
--- /dev/null
@@ -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==
index 2cf47034ff4dce2f6702cc413ba7a54683ccfd78..7098a9aaeb98d260ee73a6939273487fca317501 100644 (file)
@@ -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;
 
index 65dd2419fea38e7c518610cf97c4178e33d5094a..5c51d86f662385de6a8589311e4308af699b9eee 100644 (file)
@@ -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);
index efed5f7cf03b2c9ed296e3c9543efcb11273de65..fec2e94bfdf50b6901fdf04cdec613cd9d9b5b46 100644 (file)
@@ -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;