com php-src: Fix bug #74607: Don't check for bi-directional compatibility in traits: NEWS Zend/tests/traits/bug60217b.phpt
Zend/tests/traits/bug74607.phpt Zend/tests/traits/bug74607a.phpt Zend/tests/traits/bugs/abstract-methods05.phpt Zend/zend_inhe ritance.c
| From: | Nikita Popov | Date: | Fri, 02 Jun 2017 22:24:43 +0000 |
| Subject: | com php-src: Fix bug #74607: Don't check for bi-directional compatibility in traits: NEWS Zend/tests/traits/bug60217b.phpt Zend/tests/traits/bug74607.phpt Zend/tests/traits/bug74607a.phpt Zend/tests/traits/bugs/abstract-methods05.phpt Zend/zend_inhe ritance.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-97993@lists.php.net to get a copy of this message | ||
Commit: c6c1e75e6ba082b6d57f71c28d316b6db4fda6c7
Author: Pedro Magalhães <mail@pmmaga.net> Sun, 21 May 2017 14:41:55 +0200
Committer: Nikita Popov <nikita.ppv@gmail.com> Sat, 3 Jun 2017 00:24:43 +0200
Parents: f2e7cdb8b7a68315c902e9346f476e72370e30e1
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c6c1e75e6ba082b6d57f71c28d316b6db4fda6c7
Log:
Fix bug #74607: Don't check for bi-directional compatibility in traits
Bugs:
https://bugs.php.net/74607
Changed paths:
M NEWS
M Zend/tests/traits/bug60217b.phpt
A Zend/tests/traits/bug74607.phpt
A Zend/tests/traits/bug74607a.phpt
M Zend/tests/traits/bugs/abstract-methods05.phpt
M Zend/zend_inheritance.c
Diff:
diff --git a/NEWS b/NEWS
index 7c75a25..2a65522 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 eb852a4..8b2b64e 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 0000000..6f158db
--- /dev/null
+++ b/Zend/tests/traits/bug74607.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #74607 (Traits enforce different inheritance rules - return types)
+--FILE--
+<?php
+
+abstract class L1{
+abstract function m3($x);
+}
+
+trait L2t{
+function m3($x): int{}
+}
+
+class L2 extends L1{
+use L2t;
+}
+
+echo "DONE";
+
+?>
+--EXPECT--
+DONE
diff --git a/Zend/tests/traits/bug74607a.phpt b/Zend/tests/traits/bug74607a.phpt
new file mode 100644
index 0000000..efdced9
--- /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--
+<?php
+
+abstract class L1{
+abstract function m3($x);
+}
+
+trait L2t{
+function m3($x, $y = 0){}
+}
+
+class L2 extends L1{
+use L2t;
+}
+
+echo "DONE";
+
+?>
+--EXPECT--
+DONE
diff --git a/Zend/tests/traits/bugs/abstract-methods05.phpt
b/Zend/tests/traits/bugs/abstract-methods05.phpt
index 9a1315f..839be75 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 8f43d15..868a0bd 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)) {