From: Pedro Magalhães Date: Sun, 21 May 2017 12:41:55 +0000 (+0200) Subject: Fix bug #74607: Don't check for bi-directional compatibility in traits X-Git-Tag: php-7.2.0alpha1~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c6c1e75e6ba082b6d57f71c28d316b6db4fda6c7;p=php Fix bug #74607: Don't check for bi-directional compatibility in traits --- diff --git a/NEWS b/NEWS index 7c75a2566e..2a65522381 100644 --- a/NEWS +++ b/NEWS @@ -55,6 +55,7 @@ PHP NEWS a fatal error). (pmmaga) . Fixed bug #63384 (Cannot override an abstract method with an abstract method). (pmmaga, wes) + . Fixed bug #74607 (Traits enforce different inheritance rules). (pmmaga) . Fixed misparsing of abstract unix domain socket names. (Sara) - BCMath: diff --git a/Zend/tests/traits/bug60217b.phpt b/Zend/tests/traits/bug60217b.phpt index eb852a4fb4..8b2b64e534 100644 --- a/Zend/tests/traits/bug60217b.phpt +++ b/Zend/tests/traits/bug60217b.phpt @@ -23,4 +23,4 @@ $o = new CBroken; $o->foo(1); --EXPECTF-- -Fatal error: Declaration of TBroken2::foo($a, $b = 0) must be compatible with TBroken1::foo($a) in %s on line %d +Fatal error: Declaration of TBroken1::foo($a) must be compatible with TBroken2::foo($a, $b = 0) in %s diff --git a/Zend/tests/traits/bug74607.phpt b/Zend/tests/traits/bug74607.phpt new file mode 100644 index 0000000000..6f158db7e2 --- /dev/null +++ b/Zend/tests/traits/bug74607.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #74607 (Traits enforce different inheritance rules - return types) +--FILE-- + +--EXPECT-- +DONE diff --git a/Zend/tests/traits/bug74607a.phpt b/Zend/tests/traits/bug74607a.phpt new file mode 100644 index 0000000000..efdced95c5 --- /dev/null +++ b/Zend/tests/traits/bug74607a.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #74607 (Traits enforce different inheritance rules - number of required parameters) +--FILE-- + +--EXPECT-- +DONE diff --git a/Zend/tests/traits/bugs/abstract-methods05.phpt b/Zend/tests/traits/bugs/abstract-methods05.phpt index 9a1315f868..839be75c2b 100644 --- a/Zend/tests/traits/bugs/abstract-methods05.phpt +++ b/Zend/tests/traits/bugs/abstract-methods05.phpt @@ -22,4 +22,4 @@ class TraitsTest1 { ?> --EXPECTF-- -Fatal error: Declaration of THelloA::hello($a) must be compatible with THelloB::hello() in %s on line %d +Fatal error: Declaration of THelloB::hello() must be compatible with THelloA::hello($a) in %s on line %d diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index 8f43d15600..868a0bddf0 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -1088,7 +1088,6 @@ static zend_bool zend_traits_method_compatibility_check(zend_function *fn, zend_ uint32_t other_flags = other_fn->common.scope->ce_flags; return zend_do_perform_implementation_check(fn, other_fn) - && ((other_fn->common.scope->ce_flags & ZEND_ACC_INTERFACE) || zend_do_perform_implementation_check(other_fn, fn)) && ((fn_flags & (ZEND_ACC_FINAL|ZEND_ACC_STATIC)) == (other_flags & (ZEND_ACC_FINAL|ZEND_ACC_STATIC))); /* equal final and static qualifier */ } @@ -1158,12 +1157,13 @@ static void zend_add_trait_method(zend_class_entry *ce, const char *name, zend_s ZSTR_VAL(zend_get_function_declaration(fn)), ZSTR_VAL(zend_get_function_declaration(existing_fn))); } - } else if (fn->common.fn_flags & ZEND_ACC_ABSTRACT) { + } + if (fn->common.fn_flags & ZEND_ACC_ABSTRACT) { /* Make sure the abstract declaration is compatible with previous declaration */ if (UNEXPECTED(!zend_traits_method_compatibility_check(existing_fn, fn))) { zend_error_noreturn(E_COMPILE_ERROR, "Declaration of %s must be compatible with %s", - ZSTR_VAL(zend_get_function_declaration(fn)), - ZSTR_VAL(zend_get_function_declaration(existing_fn))); + ZSTR_VAL(zend_get_function_declaration(existing_fn)), + ZSTR_VAL(zend_get_function_declaration(fn))); } return; } @@ -1186,8 +1186,8 @@ static void zend_add_trait_method(zend_class_entry *ce, const char *name, zend_s /* Make sure the abstract declaration is compatible with previous declaration */ if (UNEXPECTED(!zend_traits_method_compatibility_check(existing_fn, fn))) { zend_error_noreturn(E_COMPILE_ERROR, "Declaration of %s must be compatible with %s", - ZSTR_VAL(zend_get_function_declaration(fn)), - ZSTR_VAL(zend_get_function_declaration(existing_fn))); + ZSTR_VAL(zend_get_function_declaration(existing_fn)), + ZSTR_VAL(zend_get_function_declaration(fn))); } return; } else if (UNEXPECTED(existing_fn->common.scope->ce_flags & ZEND_ACC_TRAIT)) {