From 780a8123fe11ef255b264b18b3482cc1a0810d61 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 1 Apr 2015 16:48:15 +0300 Subject: [PATCH] Convert fatal errors into EngineExceptions --- Zend/tests/exception_017.phpt | 36 +++++++++++++++++++++++++++++++++++ Zend/zend_API.c | 3 ++- Zend/zend_execute_API.c | 5 +++-- Zend/zend_operators.c | 4 +++- 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 Zend/tests/exception_017.phpt diff --git a/Zend/tests/exception_017.phpt b/Zend/tests/exception_017.phpt new file mode 100644 index 0000000000..9ce9ebd8c3 --- /dev/null +++ b/Zend/tests/exception_017.phpt @@ -0,0 +1,36 @@ +--TEST-- +Exceptions on improper usage of $this +--FILE-- +getMessage() . " in " , $e->getFile() . " on line " . $e->getLine() . "\n"; +} + +try { + foo("C::foo"); +} catch (EngineException $e) { + echo "\n"; + do { + echo "Exception: " . $e->getMessage() . "\n"; + $e = $e->getPrevious(); + } while ($e instanceof EngineException); +} + +C::foo(); +?> +--EXPECTF-- +Exception: Cannot call abstract method C::foo() in %sexception_017.php on line %d + +Exception: Argument 1 passed to foo() must be callable, string given, called in %sexception_017.php on line %d +Exception: Cannot call abstract method C::foo() + +Fatal error: Cannot call abstract method C::foo() in %sexception_017.php on line %d diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 37de396d1c..d10587aec1 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -3092,7 +3092,8 @@ get_function_via_handler: zend_spprintf(error, 0, "cannot call abstract method %s::%s()", fcc->calling_scope->name->val, fcc->function_handler->common.function_name->val); retval = 0; } else { - zend_error_noreturn(E_ERROR, "Cannot call abstract method %s::%s()", fcc->calling_scope->name->val, fcc->function_handler->common.function_name->val); + zend_error(E_EXCEPTION | E_ERROR, "Cannot call abstract method %s::%s()", fcc->calling_scope->name->val, fcc->function_handler->common.function_name->val); + return 0; } } else if (!fcc->object && !(fcc->function_handler->common.fn_flags & ZEND_ACC_STATIC)) { int severity; diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index dcf972b8be..fc212dbbd7 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -774,7 +774,8 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) / if (func->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED)) { if (func->common.fn_flags & ZEND_ACC_ABSTRACT) { - zend_error_noreturn(E_ERROR, "Cannot call abstract method %s::%s()", func->common.scope->name->val, func->common.function_name->val); + zend_error(E_EXCEPTION | E_ERROR, "Cannot call abstract method %s::%s()", func->common.scope->name->val, func->common.function_name->val); + return FAILURE; } if (func->common.fn_flags & ZEND_ACC_DEPRECATED) { zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated", @@ -919,7 +920,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) / fci->object->handlers->call_method(func->common.function_name, fci->object, call, fci->retval); EG(current_execute_data) = call->prev_execute_data; } else { - zend_error_noreturn(E_ERROR, "Cannot call overloaded function for non-object"); + zend_error(E_EXCEPTION | E_ERROR, "Cannot call overloaded function for non-object"); } zend_vm_stack_free_args(call); diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index daa3ada6ed..7a06fdb04c 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -1545,7 +1545,9 @@ ZEND_API int ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) / zend_string *result_str; if (op1_len > SIZE_MAX - op2_len) { - zend_error_noreturn(E_ERROR, "String size overflow"); + zend_error(E_EXCEPTION | E_ERROR, "String size overflow"); + ZVAL_FALSE(result); + return; } if (result == op1 && Z_REFCOUNTED_P(result)) { -- 2.40.0