]> granicus.if.org Git - php/commitdiff
Simplify error type filter
authortwosee <twose@qq.com>
Thu, 10 Sep 2020 09:36:04 +0000 (17:36 +0800)
committertwosee <twose@qq.com>
Thu, 10 Sep 2020 09:36:04 +0000 (17:36 +0800)
Closes GH-6049.

Zend/zend.c
ext/soap/soap.c
main/main.c
sapi/cli/php_cli_server.c
sapi/phpdbg/phpdbg.c

index 88530faa06455efa207b52ef931def885ac34aff..2a834eb6c45444bb3ef7d7ba7291649cc1ac2663 100644 (file)
@@ -1311,30 +1311,21 @@ static ZEND_COLD void zend_error_impl(
                zend_execute_data *ex;
                const zend_op *opline;
 
-               switch (type) {
-                       case E_CORE_ERROR:
-                       case E_ERROR:
-                       case E_RECOVERABLE_ERROR:
-                       case E_PARSE:
-                       case E_COMPILE_ERROR:
-                       case E_USER_ERROR:
-                               ex = EG(current_execute_data);
-                               opline = NULL;
-                               while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
-                                       ex = ex->prev_execute_data;
-                               }
-                               if (ex && ex->opline->opcode == ZEND_HANDLE_EXCEPTION &&
-                                   EG(opline_before_exception)) {
-                                       opline = EG(opline_before_exception);
-                               }
-                               zend_exception_error(EG(exception), E_WARNING);
-                               EG(exception) = NULL;
-                               if (opline) {
-                                       ex->opline = opline;
-                               }
-                               break;
-                       default:
-                               break;
+               if (type & E_FATAL_ERRORS) {
+                       ex = EG(current_execute_data);
+                       opline = NULL;
+                       while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
+                               ex = ex->prev_execute_data;
+                       }
+                       if (ex && ex->opline->opcode == ZEND_HANDLE_EXCEPTION &&
+                           EG(opline_before_exception)) {
+                               opline = EG(opline_before_exception);
+                       }
+                       zend_exception_error(EG(exception), E_WARNING);
+                       EG(exception) = NULL;
+                       if (opline) {
+                               ex->opline = opline;
+                       }
                }
        }
 
index 18dae727330c47a72d43d5c08029e7d6f2559ea5..387beb78e57d3a06e07ac72054c5b47a21e27662 100644 (file)
@@ -1843,12 +1843,7 @@ static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, c
                     use_exceptions = 1;
                }
 
-               if ((error_num == E_USER_ERROR ||
-                    error_num == E_COMPILE_ERROR ||
-                    error_num == E_CORE_ERROR ||
-                    error_num == E_ERROR ||
-                    error_num == E_PARSE) &&
-                   use_exceptions) {
+               if ((error_num & E_FATAL_ERRORS) && use_exceptions) {
                        zval fault;
                        char *code = SOAP_GLOBAL(error_code);
                        if (code == NULL) {
@@ -1870,12 +1865,7 @@ static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, c
                int fault = 0;
                zval fault_obj;
 
-               if (error_num == E_USER_ERROR ||
-                   error_num == E_COMPILE_ERROR ||
-                   error_num == E_CORE_ERROR ||
-                   error_num == E_ERROR ||
-                   error_num == E_PARSE) {
-
+               if (error_num & E_FATAL_ERRORS) {
                        char* code = SOAP_GLOBAL(error_code);
                        zend_string *buffer;
                        zval outbuf;
index 9eb610fe644099ec24c6ff5ce7e24eb5deadc885..890116e45c8a8a4422e30a46148b115ee29217c7 100644 (file)
@@ -1190,30 +1190,22 @@ static ZEND_COLD void php_error_cb(int orig_type, const char *error_filename, co
        /* according to error handling mode, throw exception or show it */
        if (EG(error_handling) == EH_THROW) {
                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:
-                       case E_DEPRECATED:
-                       case E_USER_DEPRECATED:
-                               /* 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
+                       case E_WARNING:
+                       case E_CORE_WARNING:
+                       case E_COMPILE_WARNING:
+                       case E_USER_WARNING:
+                               /* throw an exception if we are in EH_THROW mode and the type is warning.
+                                * fatal errors are real errors and cannot be made exceptions.
+                                * exclude deprecated for the sake of BC to old damaged code.
+                                * notices are no errors and are not treated as such like E_WARNINGS.
+                                * DO NOT overwrite a pending exception.
                                 */
                                if (!EG(exception)) {
                                        zend_throw_error_exception(EG(exception_class), message, 0, type);
                                }
                                return;
+                       default:
+                               break;
                }
        }
 
index 64e29e8524a3e1380217cbdbf16fb8d43ed16a80..337886bcd344a0261ac3386e253cbf95b233bdbb 100644 (file)
@@ -1177,19 +1177,13 @@ static void php_cli_server_log_response(php_cli_server_client *client, int statu
        zend_bool append_error_message = 0;
 
        if (PG(last_error_message)) {
-               switch (PG(last_error_type)) {
-                       case E_ERROR:
-                       case E_CORE_ERROR:
-                       case E_COMPILE_ERROR:
-                       case E_USER_ERROR:
-                       case E_PARSE:
-                               if (status == 200) {
-                                       /* the status code isn't changed by a fatal error, so fake it */
-                                       effective_status = 500;
-                               }
+               if (PG(last_error_type) & E_FATAL_ERRORS) {
+                       if (status == 200) {
+                               /* the status code isn't changed by a fatal error, so fake it */
+                               effective_status = 500;
+                       }
 
-                               append_error_message = 1;
-                               break;
+                       append_error_message = 1;
                }
        }
 
index d817349941b45656423dabbb62af9591cfb42b09..4629f94986fcf8f872312a1cd6e98c1ff6c78ee3 100644 (file)
@@ -798,32 +798,25 @@ static void php_sapi_phpdbg_log_message(const char *message, int syslog_type_int
                        return;
                }
 
-               switch (PG(last_error_type)) {
-                       case E_ERROR:
-                       case E_CORE_ERROR:
-                       case E_COMPILE_ERROR:
-                       case E_USER_ERROR:
-                       case E_PARSE:
-                       case E_RECOVERABLE_ERROR: {
-                               const char *file_char = zend_get_executed_filename();
-                               zend_string *file = zend_string_init(file_char, strlen(file_char), 0);
-                               phpdbg_list_file(file, 3, zend_get_executed_lineno() - 1, zend_get_executed_lineno());
-                               zend_string_release(file);
-
-                               if (!phpdbg_fully_started) {
-                                       return;
-                               }
-
-                               do {
-                                       switch (phpdbg_interactive(1, NULL)) {
-                                               case PHPDBG_LEAVE:
-                                               case PHPDBG_FINISH:
-                                               case PHPDBG_UNTIL:
-                                               case PHPDBG_NEXT:
-                                                       return;
-                                       }
-                               } while (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING));
+               if (PG(last_error_type) & E_FATAL_ERRORS) {
+                       const char *file_char = zend_get_executed_filename();
+                       zend_string *file = zend_string_init(file_char, strlen(file_char), 0);
+                       phpdbg_list_file(file, 3, zend_get_executed_lineno() - 1, zend_get_executed_lineno());
+                       zend_string_release(file);
+
+                       if (!phpdbg_fully_started) {
+                               return;
                        }
+
+                       do {
+                               switch (phpdbg_interactive(1, NULL)) {
+                                       case PHPDBG_LEAVE:
+                                       case PHPDBG_FINISH:
+                                       case PHPDBG_UNTIL:
+                                       case PHPDBG_NEXT:
+                                               return;
+                               }
+                       } while (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING));
                }
        } else {
                fprintf(stdout, "%s\n", message);