Skip to content

Commit b7fe1b6

Browse files
committed
Make argument type error message consistent for variadics
If an argument error refers to a variadic argument, we normally do not print the name of the variadic (as it is not referring to an individual argument, but to the collection of all of them). However, this was not the case for the userland argument type error message, which did it's own formatting. Closes GH-6101.
1 parent a79008b commit b7fe1b6

File tree

5 files changed

+14
-21
lines changed

5 files changed

+14
-21
lines changed

Zend/tests/arrow_functions/006.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ array(3) {
4141
[2]=>
4242
int(30)
4343
}
44-
{closure}(): Argument #2 ($args) must be of type ?int, string given, called in %s on line %d
44+
{closure}(): Argument #2 must be of type ?int, string given, called in %s on line %d

Zend/tests/function_arguments/variadic_argument_type_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ try {
1919

2020
?>
2121
--EXPECTF--
22-
foo(): Argument #2 ($bar) must be of type int, array given, called in %s on line %d
23-
foo(): Argument #4 ($bar) must be of type int, array given, called in %s on line %d
22+
foo(): Argument #2 must be of type int, array given, called in %s on line %d
23+
foo(): Argument #4 must be of type int, array given, called in %s on line %d

Zend/tests/variadic/typehint_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ array(3) {
3333
}
3434
}
3535

36-
Fatal error: Uncaught TypeError: test(): Argument #3 ($args) must be of type array, int given, called in %s:%d
36+
Fatal error: Uncaught TypeError: test(): Argument #3 must be of type array, int given, called in %s:%d
3737
Stack trace:
3838
#0 %s(%d): test(Array, Array, 2)
3939
#1 {main}

Zend/tests/variadic/typehint_suppressed_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ try {
1515

1616
?>
1717
--EXPECTF--
18-
string(%d) "test(): Argument #3 ($args) must be of type array, int given, called in %s on line %d"
18+
string(%d) "test(): Argument #3 must be of type array, int given, called in %s on line %d"

Zend/zend_execute.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -701,23 +701,16 @@ ZEND_API ZEND_COLD void zend_verify_arg_error(
701701
zend_verify_type_error_common(
702702
zf, arg_info, value, &fname, &fsep, &fclass, &need_msg, &given_msg);
703703

704-
if (zf->common.type == ZEND_USER_FUNCTION) {
705-
if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) {
706-
zend_type_error("%s%s%s(): Argument #%d ($%s) must be of type %s, %s given, called in %s on line %d",
707-
fclass, fsep, fname,
708-
arg_num, ZSTR_VAL(arg_info->name),
709-
ZSTR_VAL(need_msg), given_msg,
710-
ZSTR_VAL(ptr->func->op_array.filename), ptr->opline->lineno
711-
);
712-
} else {
713-
zend_type_error("%s%s%s(): Argument #%d ($%s) must be of type %s, %s given",
714-
fclass, fsep, fname, arg_num, ZSTR_VAL(arg_info->name), ZSTR_VAL(need_msg), given_msg
715-
);
716-
}
717-
} else {
718-
zend_type_error("%s%s%s(): Argument #%d ($%s) must be of type %s, %s given",
719-
fclass, fsep, fname, arg_num, ((zend_internal_arg_info*) arg_info)->name, ZSTR_VAL(need_msg), given_msg
704+
ZEND_ASSERT(zf->common.type == ZEND_USER_FUNCTION
705+
&& "Arginfo verification is not performed for internal functions");
706+
if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) {
707+
zend_argument_type_error(arg_num, "must be of type %s, %s given, called in %s on line %d",
708+
ZSTR_VAL(need_msg), given_msg,
709+
ZSTR_VAL(ptr->func->op_array.filename), ptr->opline->lineno
720710
);
711+
} else {
712+
zend_argument_type_error(arg_num,
713+
"must be of type %s, %s given", ZSTR_VAL(need_msg), given_msg);
721714
}
722715

723716
zend_string_release(need_msg);

0 commit comments

Comments
 (0)