Skip to content

Commit bd1d11d

Browse files
committed
Simplify error type filter
Closes GH-6049.
1 parent 298d2db commit bd1d11d

File tree

5 files changed

+52
-92
lines changed

5 files changed

+52
-92
lines changed

Zend/zend.c

+15-24
Original file line numberDiff line numberDiff line change
@@ -1311,30 +1311,21 @@ static ZEND_COLD void zend_error_impl(
13111311
zend_execute_data *ex;
13121312
const zend_op *opline;
13131313

1314-
switch (type) {
1315-
case E_CORE_ERROR:
1316-
case E_ERROR:
1317-
case E_RECOVERABLE_ERROR:
1318-
case E_PARSE:
1319-
case E_COMPILE_ERROR:
1320-
case E_USER_ERROR:
1321-
ex = EG(current_execute_data);
1322-
opline = NULL;
1323-
while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
1324-
ex = ex->prev_execute_data;
1325-
}
1326-
if (ex && ex->opline->opcode == ZEND_HANDLE_EXCEPTION &&
1327-
EG(opline_before_exception)) {
1328-
opline = EG(opline_before_exception);
1329-
}
1330-
zend_exception_error(EG(exception), E_WARNING);
1331-
EG(exception) = NULL;
1332-
if (opline) {
1333-
ex->opline = opline;
1334-
}
1335-
break;
1336-
default:
1337-
break;
1314+
if (type & E_FATAL_ERRORS) {
1315+
ex = EG(current_execute_data);
1316+
opline = NULL;
1317+
while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
1318+
ex = ex->prev_execute_data;
1319+
}
1320+
if (ex && ex->opline->opcode == ZEND_HANDLE_EXCEPTION &&
1321+
EG(opline_before_exception)) {
1322+
opline = EG(opline_before_exception);
1323+
}
1324+
zend_exception_error(EG(exception), E_WARNING);
1325+
EG(exception) = NULL;
1326+
if (opline) {
1327+
ex->opline = opline;
1328+
}
13381329
}
13391330
}
13401331

ext/soap/soap.c

+2-12
Original file line numberDiff line numberDiff line change
@@ -1843,12 +1843,7 @@ static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, c
18431843
use_exceptions = 1;
18441844
}
18451845

1846-
if ((error_num == E_USER_ERROR ||
1847-
error_num == E_COMPILE_ERROR ||
1848-
error_num == E_CORE_ERROR ||
1849-
error_num == E_ERROR ||
1850-
error_num == E_PARSE) &&
1851-
use_exceptions) {
1846+
if ((error_num & E_FATAL_ERRORS) && use_exceptions) {
18521847
zval fault;
18531848
char *code = SOAP_GLOBAL(error_code);
18541849
if (code == NULL) {
@@ -1870,12 +1865,7 @@ static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, c
18701865
int fault = 0;
18711866
zval fault_obj;
18721867

1873-
if (error_num == E_USER_ERROR ||
1874-
error_num == E_COMPILE_ERROR ||
1875-
error_num == E_CORE_ERROR ||
1876-
error_num == E_ERROR ||
1877-
error_num == E_PARSE) {
1878-
1868+
if (error_num & E_FATAL_ERRORS) {
18791869
char* code = SOAP_GLOBAL(error_code);
18801870
zend_string *buffer;
18811871
zval outbuf;

main/main.c

+11-19
Original file line numberDiff line numberDiff line change
@@ -1190,30 +1190,22 @@ static ZEND_COLD void php_error_cb(int orig_type, const char *error_filename, co
11901190
/* according to error handling mode, throw exception or show it */
11911191
if (EG(error_handling) == EH_THROW) {
11921192
switch (type) {
1193-
case E_ERROR:
1194-
case E_CORE_ERROR:
1195-
case E_COMPILE_ERROR:
1196-
case E_USER_ERROR:
1197-
case E_PARSE:
1198-
/* fatal errors are real errors and cannot be made exceptions */
1199-
break;
1200-
case E_STRICT:
1201-
case E_DEPRECATED:
1202-
case E_USER_DEPRECATED:
1203-
/* for the sake of BC to old damaged code */
1204-
break;
1205-
case E_NOTICE:
1206-
case E_USER_NOTICE:
1207-
/* notices are no errors and are not treated as such like E_WARNINGS */
1208-
break;
1209-
default:
1210-
/* throw an exception if we are in EH_THROW mode
1211-
* but DO NOT overwrite a pending exception
1193+
case E_WARNING:
1194+
case E_CORE_WARNING:
1195+
case E_COMPILE_WARNING:
1196+
case E_USER_WARNING:
1197+
/* throw an exception if we are in EH_THROW mode and the type is warning.
1198+
* fatal errors are real errors and cannot be made exceptions.
1199+
* exclude deprecated for the sake of BC to old damaged code.
1200+
* notices are no errors and are not treated as such like E_WARNINGS.
1201+
* DO NOT overwrite a pending exception.
12121202
*/
12131203
if (!EG(exception)) {
12141204
zend_throw_error_exception(EG(exception_class), message, 0, type);
12151205
}
12161206
return;
1207+
default:
1208+
break;
12171209
}
12181210
}
12191211

sapi/cli/php_cli_server.c

+6-12
Original file line numberDiff line numberDiff line change
@@ -1177,19 +1177,13 @@ static void php_cli_server_log_response(php_cli_server_client *client, int statu
11771177
zend_bool append_error_message = 0;
11781178

11791179
if (PG(last_error_message)) {
1180-
switch (PG(last_error_type)) {
1181-
case E_ERROR:
1182-
case E_CORE_ERROR:
1183-
case E_COMPILE_ERROR:
1184-
case E_USER_ERROR:
1185-
case E_PARSE:
1186-
if (status == 200) {
1187-
/* the status code isn't changed by a fatal error, so fake it */
1188-
effective_status = 500;
1189-
}
1180+
if (PG(last_error_type) & E_FATAL_ERRORS) {
1181+
if (status == 200) {
1182+
/* the status code isn't changed by a fatal error, so fake it */
1183+
effective_status = 500;
1184+
}
11901185

1191-
append_error_message = 1;
1192-
break;
1186+
append_error_message = 1;
11931187
}
11941188
}
11951189

sapi/phpdbg/phpdbg.c

+18-25
Original file line numberDiff line numberDiff line change
@@ -798,32 +798,25 @@ static void php_sapi_phpdbg_log_message(const char *message, int syslog_type_int
798798
return;
799799
}
800800

801-
switch (PG(last_error_type)) {
802-
case E_ERROR:
803-
case E_CORE_ERROR:
804-
case E_COMPILE_ERROR:
805-
case E_USER_ERROR:
806-
case E_PARSE:
807-
case E_RECOVERABLE_ERROR: {
808-
const char *file_char = zend_get_executed_filename();
809-
zend_string *file = zend_string_init(file_char, strlen(file_char), 0);
810-
phpdbg_list_file(file, 3, zend_get_executed_lineno() - 1, zend_get_executed_lineno());
811-
zend_string_release(file);
812-
813-
if (!phpdbg_fully_started) {
814-
return;
815-
}
816-
817-
do {
818-
switch (phpdbg_interactive(1, NULL)) {
819-
case PHPDBG_LEAVE:
820-
case PHPDBG_FINISH:
821-
case PHPDBG_UNTIL:
822-
case PHPDBG_NEXT:
823-
return;
824-
}
825-
} while (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING));
801+
if (PG(last_error_type) & E_FATAL_ERRORS) {
802+
const char *file_char = zend_get_executed_filename();
803+
zend_string *file = zend_string_init(file_char, strlen(file_char), 0);
804+
phpdbg_list_file(file, 3, zend_get_executed_lineno() - 1, zend_get_executed_lineno());
805+
zend_string_release(file);
806+
807+
if (!phpdbg_fully_started) {
808+
return;
826809
}
810+
811+
do {
812+
switch (phpdbg_interactive(1, NULL)) {
813+
case PHPDBG_LEAVE:
814+
case PHPDBG_FINISH:
815+
case PHPDBG_UNTIL:
816+
case PHPDBG_NEXT:
817+
return;
818+
}
819+
} while (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING));
827820
}
828821
} else {
829822
fprintf(stdout, "%s\n", message);

0 commit comments

Comments
 (0)