Skip to content

Make argument type error message consistent for variadics #6101

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 1 commit 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
2 changes: 1 addition & 1 deletion Zend/tests/arrow_functions/006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ array(3) {
[2]=>
int(30)
}
{closure}(): Argument #2 ($args) must be of type ?int, string given, called in %s on line %d
{closure}(): Argument #2 must be of type ?int, string given, called in %s on line %d
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ try {

?>
--EXPECTF--
foo(): Argument #2 ($bar) must be of type int, array given, called in %s on line %d
foo(): Argument #4 ($bar) must be of type int, array given, called in %s on line %d
foo(): Argument #2 must be of type int, array given, called in %s on line %d
foo(): Argument #4 must be of type int, array given, called in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/variadic/typehint_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ array(3) {
}
}

Fatal error: Uncaught TypeError: test(): Argument #3 ($args) must be of type array, int given, called in %s:%d
Fatal error: Uncaught TypeError: test(): Argument #3 must be of type array, int given, called in %s:%d
Stack trace:
#0 %s(%d): test(Array, Array, 2)
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/variadic/typehint_suppressed_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ try {

?>
--EXPECTF--
string(%d) "test(): Argument #3 ($args) must be of type array, int given, called in %s on line %d"
string(%d) "test(): Argument #3 must be of type array, int given, called in %s on line %d"
25 changes: 9 additions & 16 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,23 +701,16 @@ ZEND_API ZEND_COLD void zend_verify_arg_error(
zend_verify_type_error_common(
zf, arg_info, value, &fname, &fsep, &fclass, &need_msg, &given_msg);

if (zf->common.type == ZEND_USER_FUNCTION) {
if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) {
zend_type_error("%s%s%s(): Argument #%d ($%s) must be of type %s, %s given, called in %s on line %d",
fclass, fsep, fname,
arg_num, ZSTR_VAL(arg_info->name),
ZSTR_VAL(need_msg), given_msg,
ZSTR_VAL(ptr->func->op_array.filename), ptr->opline->lineno
);
} else {
zend_type_error("%s%s%s(): Argument #%d ($%s) must be of type %s, %s given",
fclass, fsep, fname, arg_num, ZSTR_VAL(arg_info->name), ZSTR_VAL(need_msg), given_msg
);
}
} else {
zend_type_error("%s%s%s(): Argument #%d ($%s) must be of type %s, %s given",
fclass, fsep, fname, arg_num, ((zend_internal_arg_info*) arg_info)->name, ZSTR_VAL(need_msg), given_msg
ZEND_ASSERT(zf->common.type == ZEND_USER_FUNCTION
&& "Arginfo verification is not performed for internal functions");
if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) {
zend_argument_type_error(arg_num, "must be of type %s, %s given, called in %s on line %d",
ZSTR_VAL(need_msg), given_msg,
ZSTR_VAL(ptr->func->op_array.filename), ptr->opline->lineno
);
} else {
zend_argument_type_error(arg_num,
"must be of type %s, %s given", ZSTR_VAL(need_msg), given_msg);
}

zend_string_release(need_msg);
Expand Down