Skip to content

Commit e42f342

Browse files
committed
Deprecate passing null to internal scalar arg
1 parent 1cd33d8 commit e42f342

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Zend/zend_API.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,20 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_class(zval *arg, zend_class_entry **p
426426
}
427427
/* }}} */
428428

429+
static ZEND_COLD bool zend_null_arg_deprecated(const char *type) {
430+
zend_string *func_name = get_active_function_or_method_name();
431+
zend_error(E_DEPRECATED, "%s(): Passing null to argument of type %s is deprecated",
432+
ZSTR_VAL(func_name), type);
433+
zend_string_release(func_name);
434+
return !EG(exception);
435+
}
436+
429437
ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_weak(zval *arg, bool *dest) /* {{{ */
430438
{
431439
if (EXPECTED(Z_TYPE_P(arg) <= IS_STRING)) {
440+
if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) && !zend_null_arg_deprecated("bool")) {
441+
return 0;
442+
}
432443
*dest = zend_is_true(arg);
433444
} else {
434445
return 0;
@@ -479,6 +490,9 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_weak(zval *arg, zend_long *dest)
479490
return 0;
480491
}
481492
} else if (EXPECTED(Z_TYPE_P(arg) < IS_TRUE)) {
493+
if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) && !zend_null_arg_deprecated("int")) {
494+
return 0;
495+
}
482496
*dest = 0;
483497
} else if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
484498
*dest = 1;
@@ -517,6 +531,9 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_double_weak(zval *arg, double *dest)
517531
return 0;
518532
}
519533
} else if (EXPECTED(Z_TYPE_P(arg) < IS_TRUE)) {
534+
if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) && !zend_null_arg_deprecated("float")) {
535+
return 0;
536+
}
520537
*dest = 0.0;
521538
} else if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
522539
*dest = 1.0;
@@ -572,6 +589,9 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_number_slow(zval *arg, zval **dest) /
572589
ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **dest) /* {{{ */
573590
{
574591
if (EXPECTED(Z_TYPE_P(arg) < IS_STRING)) {
592+
if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) && !zend_null_arg_deprecated("string")) {
593+
return 0;
594+
}
575595
convert_to_string(arg);
576596
*dest = Z_STR_P(arg);
577597
} else if (UNEXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {

0 commit comments

Comments
 (0)