Skip to content

Simplify error type filter #6049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 15 additions & 24 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1310,30 +1310,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;
}
}
}

Expand Down
14 changes: 2 additions & 12 deletions ext/soap/soap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1842,12 +1842,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) {
Expand All @@ -1869,12 +1864,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;
Expand Down
30 changes: 11 additions & 19 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1225,30 +1225,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;
}
}

Expand Down
18 changes: 6 additions & 12 deletions sapi/cli/php_cli_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,19 +1169,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;
}
}

Expand Down
43 changes: 18 additions & 25 deletions sapi/phpdbg/phpdbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down