Skip to content

Commit 8446aed

Browse files
committed
Do not re-issue inheritance *warnings* at runtime
Fix bad error message
1 parent 9eba1d8 commit 8446aed

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

Zend/zend_inheritance.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,27 +1998,17 @@ ZEND_API void zend_do_link_class(zend_class_entry *ce, zend_class_entry *parent)
19981998

19991999
static void _inheritance_runtime_error_msg(zend_function *child, zend_function *parent)
20002000
{
2001-
int error_level;
2002-
const char *error_verb;
2003-
zend_string *method_prototype = zend_get_function_declaration(parent);
2004-
zend_string *child_prototype = zend_get_function_declaration(child);
2005-
2006-
if (child->common.prototype && (
2007-
child->common.prototype->common.fn_flags & ZEND_ACC_ABSTRACT
2008-
)) {
2009-
error_level = E_ERROR;
2010-
error_verb = "must";
2011-
} else if ((parent->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) &&
2012-
!_check_inherited_return_type(child, child->common.arg_info - 1, parent, parent->common.arg_info - 1)) {
2013-
error_level = E_ERROR;
2014-
error_verb = "must";
2015-
} else {
2016-
error_level = E_WARNING;
2017-
error_verb = "should";
2001+
zend_function *proto = child->common.prototype;
2002+
if ((proto && (proto->common.fn_flags & ZEND_ACC_ABSTRACT))
2003+
|| ((parent->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE)
2004+
&& !_check_inherited_return_type(child, child->common.arg_info - 1, parent, parent->common.arg_info - 1)))
2005+
{
2006+
zend_string *method_prototype = zend_get_function_declaration(parent);
2007+
zend_string *child_prototype = zend_get_function_declaration(child);
2008+
zend_error(E_ERROR, "Declaration of %s must be compatible with %s", ZSTR_VAL(child_prototype), ZSTR_VAL(method_prototype));
2009+
zend_string_efree(child_prototype);
2010+
zend_string_efree(method_prototype);
20182011
}
2019-
zend_error(error_level, "Declaration of %s %s be compatible with %s", ZSTR_VAL(child_prototype), error_verb, ZSTR_VAL(method_prototype));
2020-
zend_string_efree(child_prototype);
2021-
zend_string_efree(method_prototype);
20222012
}
20232013

20242014
ZEND_API void zend_verify_variance(zend_class_entry *ce) /* {{{ */
@@ -2093,7 +2083,9 @@ ZEND_API void zend_verify_variance(zend_class_entry *ce) /* {{{ */
20932083
parent, parent_arg_info);
20942084

20952085
if (check < 0) {
2096-
zend_error_noreturn(E_ERROR, "Bad arg!");
2086+
_inheritance_runtime_error_msg(child, parent);
2087+
// todo: what to do with errors, not warnings?
2088+
continue;
20972089
}
20982090
}
20992091

0 commit comments

Comments
 (0)