Skip to content

Commit 1468d2a

Browse files
committed
Throw notice on param name mismatch
1 parent bc09012 commit 1468d2a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Zend/zend_inheritance.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,18 @@ static inheritance_status zend_do_perform_arg_type_hint_check(
516516
}
517517
/* }}} */
518518

519+
static const char *get_arg_name(
520+
const zend_function *fe, const zend_arg_info *arg_info, size_t *len) {
521+
if (fe->type == ZEND_INTERNAL_FUNCTION) {
522+
zend_internal_arg_info *internal_arg_info = (zend_internal_arg_info *) arg_info;
523+
*len = strlen(internal_arg_info->name);
524+
return internal_arg_info->name;
525+
} else {
526+
*len = ZSTR_LEN(arg_info->name);
527+
return ZSTR_VAL(arg_info->name);
528+
}
529+
}
530+
519531
static inheritance_status zend_do_perform_implementation_check(
520532
const zend_function *fe, const zend_function *proto) /* {{{ */
521533
{
@@ -592,6 +604,20 @@ static inheritance_status zend_do_perform_implementation_check(
592604
if (ZEND_ARG_SEND_MODE(fe_arg_info) != ZEND_ARG_SEND_MODE(proto_arg_info)) {
593605
return INHERITANCE_ERROR;
594606
}
607+
608+
// TODO: We may get duplicate errors for UNRESOLVED.
609+
size_t proto_name_len, fe_name_len;
610+
const char *proto_name = get_arg_name(proto, proto_arg_info, &proto_name_len);
611+
const char *fe_name = get_arg_name(fe, fe_arg_info, &fe_name_len);
612+
if (proto_name_len != fe_name_len || memcmp(proto_name, fe_name, proto_name_len)) {
613+
zend_error(E_NOTICE,
614+
"Parameter $%s of %s::%s() has been renamed to $%s in %s::%s(), "
615+
"which may break named parameters",
616+
proto_name,
617+
ZSTR_VAL(proto->common.scope->name), ZSTR_VAL(proto->common.function_name),
618+
fe_name,
619+
ZSTR_VAL(fe->common.scope->name), ZSTR_VAL(fe->common.function_name));
620+
}
595621
}
596622

597623
/* Check return type compatibility, but only if the prototype already specifies

0 commit comments

Comments
 (0)