Skip to content

Commit 22c38b2

Browse files
committed
Remove need to pass error level
1 parent 5a99c07 commit 22c38b2

16 files changed

+938
-941
lines changed

Zend/zend.c

+8-13
Original file line numberDiff line numberDiff line change
@@ -1292,26 +1292,21 @@ ZEND_API ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ..
12921292
# endif
12931293
#endif
12941294

1295-
ZEND_API void zend_throw_error(zend_class_entry *exception_ce, int type, const char *format, ...) /* {{{ */
1295+
ZEND_API void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) /* {{{ */
12961296
{
12971297
va_list va;
12981298
char *message = NULL;
1299-
1299+
13001300
va_start(va, format);
13011301
zend_vspprintf(&message, 0, format, va);
13021302

1303-
if (type & E_EXCEPTION) {
1304-
type = E_ERROR; // Convert to E_ERROR if unable to throw.
1305-
//TODO: we can't convert compile-time errors to exceptions yet???
1306-
if (EG(current_execute_data) && !CG(in_compilation)) {
1307-
zend_throw_exception(exception_ce, message, type);
1308-
efree(message);
1309-
va_end(va);
1310-
return;
1311-
}
1303+
// TODO: we can't convert compile-time errors to exceptions yet???
1304+
if (EG(current_execute_data) && !CG(in_compilation)) {
1305+
zend_throw_exception(exception_ce, message, E_ERROR);
1306+
} else {
1307+
zend_error(E_ERROR, message);
13121308
}
1313-
1314-
zend_error(type, message);
1309+
13151310
efree(message);
13161311
va_end(va);
13171312
}

Zend/zend.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
285285
extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, int filename_len);
286286

287287
ZEND_API void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
288-
ZEND_API void zend_throw_error(zend_class_entry *exception_ce, int type, const char *format, ...);
288+
ZEND_API void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...);
289289
ZEND_API void zend_type_error(const char *format, ...);
290290
ZEND_API void zend_internal_type_error(zend_bool throw_exception, const char *format, ...);
291291

Zend/zend_API.c

+15-8
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,11 @@ ZEND_API void ZEND_FASTCALL zend_wrong_callback_error(int severity, int num, cha
244244
if (severity == E_WARNING) {
245245
zend_internal_type_error(ZEND_ARG_USES_STRICT_TYPES(), "%s%s%s() expects parameter %d to be a valid callback, %s",
246246
class_name, space, get_active_function_name(), num, error);
247+
} else if (severity == E_ERROR) {
248+
zend_throw_error(zend_ce_error, "%s%s%s() expects parameter %d to be a valid callback, %s",
249+
class_name, space, get_active_function_name(), num, error);
247250
} else {
248-
zend_throw_error(zend_ce_error, severity, "%s%s%s() expects parameter %d to be a valid callback, %s",
251+
zend_error(severity, "%s%s%s() expects parameter %d to be a valid callback, %s",
249252
class_name, space, get_active_function_name(), num, error);
250253
}
251254
efree(error);
@@ -710,7 +713,7 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons
710713
break;
711714
} else {
712715
if (is_callable_error) {
713-
*severity = E_EXCEPTION;
716+
*severity = E_ERROR;
714717
zend_spprintf(error, 0, "to be a valid callback, %s", is_callable_error);
715718
efree(is_callable_error);
716719
return "";
@@ -1273,11 +1276,11 @@ ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *class_type
12731276
{
12741277
if (UNEXPECTED(class_type->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) {
12751278
if (class_type->ce_flags & ZEND_ACC_INTERFACE) {
1276-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Cannot instantiate interface %s", ZSTR_VAL(class_type->name));
1279+
zend_throw_error(zend_ce_error, "Cannot instantiate interface %s", ZSTR_VAL(class_type->name));
12771280
} else if (class_type->ce_flags & ZEND_ACC_TRAIT) {
1278-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Cannot instantiate trait %s", ZSTR_VAL(class_type->name));
1281+
zend_throw_error(zend_ce_error, "Cannot instantiate trait %s", ZSTR_VAL(class_type->name));
12791282
} else {
1280-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Cannot instantiate abstract class %s", ZSTR_VAL(class_type->name));
1283+
zend_throw_error(zend_ce_error, "Cannot instantiate abstract class %s", ZSTR_VAL(class_type->name));
12811284
}
12821285
ZVAL_NULL(arg);
12831286
Z_OBJ_P(arg) = NULL;
@@ -3104,7 +3107,7 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
31043107
zend_spprintf(error, 0, "cannot call abstract method %s::%s()", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name));
31053108
retval = 0;
31063109
} else {
3107-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Cannot call abstract method %s::%s()", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name));
3110+
zend_throw_error(zend_ce_error, "Cannot call abstract method %s::%s()", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name));
31083111
return 0;
31093112
}
31103113
} else if (!fcc->object && !(fcc->function_handler->common.fn_flags & ZEND_ACC_STATIC)) {
@@ -3115,7 +3118,7 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
31153118
verb = "should not";
31163119
} else {
31173120
/* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */
3118-
severity = E_EXCEPTION;
3121+
severity = E_ERROR;
31193122
verb = "cannot";
31203123
}
31213124
if ((check_flags & IS_CALLABLE_CHECK_IS_STATIC) != 0) {
@@ -3127,7 +3130,11 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
31273130
retval = 0;
31283131
}
31293132
} else if (retval) {
3130-
zend_throw_error(zend_ce_error, severity, "Non-static method %s::%s() %s be called statically", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name), verb);
3133+
if (severity == E_ERROR) {
3134+
zend_throw_error(zend_ce_error, "Non-static method %s::%s() %s be called statically", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name), verb);
3135+
} else {
3136+
zend_error(severity, "Non-static method %s::%s() %s be called statically", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(fcc->function_handler->common.function_name), verb);
3137+
}
31313138
}
31323139
}
31333140
if (retval && (check_flags & IS_CALLABLE_CHECK_NO_ACCESS) == 0) {

Zend/zend_ast.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static int zend_ast_add_array_element(zval *result, zval *offset, zval *expr)
203203
zend_hash_index_update(Z_ARRVAL_P(result), zend_dval_to_lval(Z_DVAL_P(offset)), expr);
204204
break;
205205
default:
206-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Illegal offset type");
206+
zend_throw_error(zend_ce_error, "Illegal offset type");
207207
return FAILURE;
208208
}
209209
return SUCCESS;
@@ -405,7 +405,7 @@ ZEND_API int zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *sc
405405
}
406406
break;
407407
default:
408-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Unsupported constant expression");
408+
zend_throw_error(zend_ce_error, "Unsupported constant expression");
409409
ret = FAILURE;
410410
}
411411
return ret;

Zend/zend_closures.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define ZEND_CLOSURE_PRINT_NAME "Closure object"
3333

3434
#define ZEND_CLOSURE_PROPERTY_ERROR() \
35-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Closure object cannot have properties")
35+
zend_throw_error(zend_ce_error, "Closure object cannot have properties")
3636

3737
typedef struct _zend_closure {
3838
zend_object std;
@@ -53,7 +53,7 @@ ZEND_METHOD(Closure, __invoke) /* {{{ */
5353
arguments = emalloc(sizeof(zval) * ZEND_NUM_ARGS());
5454
if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), arguments) == FAILURE) {
5555
efree(arguments);
56-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Cannot get arguments for calling closure");
56+
zend_throw_error(zend_ce_error, "Cannot get arguments for calling closure");
5757
RETVAL_FALSE;
5858
} else if (call_user_function_ex(CG(function_table), NULL, getThis(), return_value, ZEND_NUM_ARGS(), arguments, 1, NULL) == FAILURE) {
5959
RETVAL_FALSE;
@@ -207,7 +207,7 @@ ZEND_METHOD(Closure, bind)
207207

208208
static zend_function *zend_closure_get_constructor(zend_object *object) /* {{{ */
209209
{
210-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Instantiation of 'Closure' is not allowed");
210+
zend_throw_error(zend_ce_error, "Instantiation of 'Closure' is not allowed");
211211
return NULL;
212212
}
213213
/* }}} */
@@ -450,7 +450,7 @@ static HashTable *zend_closure_get_gc(zval *obj, zval **table, int *n) /* {{{ */
450450
Private constructor preventing instantiation */
451451
ZEND_METHOD(Closure, __construct)
452452
{
453-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Instantiation of 'Closure' is not allowed");
453+
zend_throw_error(zend_ce_error, "Instantiation of 'Closure' is not allowed");
454454
}
455455
/* }}} */
456456

Zend/zend_constants.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -333,17 +333,17 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
333333
if (class_name_len == sizeof("self")-1 &&
334334
!memcmp(lcname, "self", sizeof("self")-1)) {
335335
if (UNEXPECTED(!scope)) {
336-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Cannot access self:: when no class scope is active");
336+
zend_throw_error(zend_ce_error, "Cannot access self:: when no class scope is active");
337337
return NULL;
338338
}
339339
ce = scope;
340340
} else if (class_name_len == sizeof("parent")-1 &&
341341
!memcmp(lcname, "parent", sizeof("parent")-1)) {
342342
if (UNEXPECTED(!scope)) {
343-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Cannot access parent:: when no class scope is active");
343+
zend_throw_error(zend_ce_error, "Cannot access parent:: when no class scope is active");
344344
return NULL;
345345
} else if (UNEXPECTED(!scope->parent)) {
346-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Cannot access parent:: when current class scope has no parent");
346+
zend_throw_error(zend_ce_error, "Cannot access parent:: when current class scope has no parent");
347347
return NULL;
348348
} else {
349349
ce = scope->parent;
@@ -352,7 +352,7 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
352352
!memcmp(lcname, "static", sizeof("static")-1)) {
353353
ce = zend_get_called_scope(EG(current_execute_data));
354354
if (UNEXPECTED(!ce)) {
355-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Cannot access static:: when no class scope is active");
355+
zend_throw_error(zend_ce_error, "Cannot access static:: when no class scope is active");
356356
return NULL;
357357
}
358358
} else {
@@ -363,7 +363,7 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
363363
ret_constant = zend_hash_find(&ce->constants_table, constant_name);
364364
if (ret_constant == NULL) {
365365
if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
366-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Undefined class constant '%s::%s'", ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
366+
zend_throw_error(zend_ce_error, "Undefined class constant '%s::%s'", ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
367367
zend_string_release(class_name);
368368
zend_string_free(constant_name);
369369
return NULL;

Zend/zend_exceptions.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ ZEND_METHOD(exception, __construct)
261261
} else {
262262
ce = base_ce;
263263
}
264-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Wrong parameters for %s([string $message [, long $code [, Throwable $previous = NULL]]])", ZSTR_VAL(ce->name));
264+
zend_throw_error(zend_ce_error, "Wrong parameters for %s([string $message [, long $code [, Throwable $previous = NULL]]])", ZSTR_VAL(ce->name));
265265
return;
266266
}
267267

@@ -297,7 +297,7 @@ ZEND_METHOD(error_exception, __construct)
297297
} else {
298298
ce = zend_ce_error_exception;
299299
}
300-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Wrong parameters for %s([string $message [, long $code, [ long $severity, [ string $filename, [ long $lineno [, Throwable $previous = NULL]]]]]])", ZSTR_VAL(ce->name));
300+
zend_throw_error(zend_ce_error, "Wrong parameters for %s([string $message [, long $code, [ long $severity, [ string $filename, [ long $lineno [, Throwable $previous = NULL]]]]]])", ZSTR_VAL(ce->name));
301301
return;
302302
}
303303

@@ -1033,7 +1033,7 @@ ZEND_API void zend_throw_exception_object(zval *exception) /* {{{ */
10331033
exception_ce = Z_OBJCE_P(exception);
10341034

10351035
if (!exception_ce || !instanceof_function(exception_ce, zend_ce_throwable)) {
1036-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Cannot throw objects that do not implement Throwable");
1036+
zend_throw_error(zend_ce_error, "Cannot throw objects that do not implement Throwable");
10371037
return;
10381038
}
10391039
zend_throw_exception_internal(exception);

Zend/zend_execute.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ static zend_never_inline void zend_assign_to_object_dim(zval *retval, zval *obje
12011201

12021202
/* Note: property_name in this case is really the array index! */
12031203
if (!Z_OBJ_HT_P(object)->write_dimension) {
1204-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Cannot use object as array");
1204+
zend_throw_error(zend_ce_error, "Cannot use object as array");
12051205
FREE_OP(free_value);
12061206
return;
12071207
}
@@ -1681,15 +1681,15 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
16811681
}
16821682

16831683
if (dim == NULL) {
1684-
zend_throw_error(zend_ce_error, E_EXCEPTION, "[] operator not supported for strings");
1684+
zend_throw_error(zend_ce_error, "[] operator not supported for strings");
16851685
ZVAL_NULL(result);
16861686
} else {
16871687
zend_check_string_offset(dim, type);
16881688
ZVAL_INDIRECT(result, NULL); /* wrong string offset */
16891689
}
16901690
} else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
16911691
if (!Z_OBJ_HT_P(container)->read_dimension) {
1692-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Cannot use object as array");
1692+
zend_throw_error(zend_ce_error, "Cannot use object as array");
16931693
retval = &EG(error_zval);
16941694
} else {
16951695
retval = Z_OBJ_HT_P(container)->read_dimension(container, dim, type, result);
@@ -1830,7 +1830,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
18301830
}
18311831
} else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
18321832
if (!Z_OBJ_HT_P(container)->read_dimension) {
1833-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Cannot use object as array");
1833+
zend_throw_error(zend_ce_error, "Cannot use object as array");
18341834
ZVAL_NULL(result);
18351835
} else {
18361836
retval = Z_OBJ_HT_P(container)->read_dimension(container, dim, type, result);
@@ -1922,7 +1922,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
19221922
ZVAL_INDIRECT(result, ptr);
19231923
}
19241924
} else {
1925-
zend_throw_error(zend_ce_error, E_EXCEPTION, "Cannot access undefined property for object with overloaded property access");
1925+
zend_throw_error(zend_ce_error, "Cannot access undefined property for object with overloaded property access");
19261926
ZVAL_INDIRECT(result, &EG(error_zval));
19271927
}
19281928
} else {

0 commit comments

Comments
 (0)