diff --git a/Zend/tests/interfaces/gh25759.phpt b/Zend/tests/interfaces/gh25759.phpt new file mode 100644 index 000000000000..e8de48076d97 --- /dev/null +++ b/Zend/tests/interfaces/gh25759.phpt @@ -0,0 +1,44 @@ +--TEST-- +GH-25759: Interface method compatibility is independent of extends order +--FILE-- +getValue()); +var_dump((new ValueFirstImplementation())->getValue()); +?> +--EXPECT-- +int(42) +int(42) diff --git a/Zend/tests/interfaces/gh25759_2.phpt b/Zend/tests/interfaces/gh25759_2.phpt new file mode 100644 index 000000000000..47b08d653b4f --- /dev/null +++ b/Zend/tests/interfaces/gh25759_2.phpt @@ -0,0 +1,28 @@ +--TEST-- +GH-25759: Interface method merging retains the most restrictive return type +--FILE-- + +--EXPECTF-- +Fatal error: Declaration of InvalidImplementation::getValue(): ?int must be compatible with HasValue::getValue(): int in %s on line %d diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index 9e9e247faefd..b72ea6dcf47e 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -1253,6 +1253,19 @@ static void do_inherit_method(zend_string *key, zend_function *parent, zend_clas return; } + if (is_interface && (ce->ce_flags & ZEND_ACC_INTERFACE) + && func->common.scope != ce + && (func->common.fn_flags & ZEND_ACC_ABSTRACT) + && (parent->common.fn_flags & ZEND_ACC_ABSTRACT) + && (func->common.fn_flags & ZEND_ACC_STATIC) == (parent->common.fn_flags & ZEND_ACC_STATIC) + && zend_do_perform_implementation_check( + parent, parent->common.scope, func, func->common.scope) == INHERITANCE_SUCCESS + && zend_do_perform_implementation_check( + func, func->common.scope, parent, parent->common.scope) != INHERITANCE_SUCCESS) { + Z_PTR_P(child) = zend_duplicate_function(parent, ce); + return; + } + do_inheritance_check_on_method( func, func->common.scope, parent, parent->common.scope, ce, child, flags); } else {